org.onlab.packet.Ip6Prefix Java Examples

The following examples show how to use org.onlab.packet.Ip6Prefix. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AclRule.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new ACL rule.
 *
 * @param srcIp     source IP address
 * @param srcMac    source Mac address
 * @param dstMac    destination Mac address
 * @param dstIp     destination IP address
 * @param ipProto   IP protocol
 * @param dscp      IP dscp
 * @param dstTpPort destination transport layer port
 * @param srcTpPort source transport layer port
 * @param action    ACL rule's action
 */
private AclRule(MacAddress srcMac, MacAddress dstMac, Ip4Prefix srcIp, Ip4Prefix dstIp,
                Ip6Prefix srcIp6, Ip6Prefix dstIp6, byte ipProto, byte dscp,
                short dstTpPort, short srcTpPort, Action action) {
    synchronized (ID_GENERATOR_LOCK) {
        checkState(idGenerator != null, "Id generator is not bound.");
        this.id = RuleId.valueOf(idGenerator.getNewId());
    }
    this.srcMac = srcMac;
    this.dstMac = dstMac;
    this.srcIp = srcIp;
    this.dstIp = dstIp;
    this.srcIp6 = srcIp6;
    this.dstIp6 = dstIp6;
    this.ipProto = ipProto;
    this.dscp = dscp;
    this.dstTpPort = dstTpPort;
    this.srcTpPort = srcTpPort;
    this.action = action;
}
 
Example #2
Source File: RouteEntryTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests equality of {@link RouteEntry}.
 */
@Test
public void testEquality() {
    Ip4Prefix prefix1 = Ip4Prefix.valueOf("1.2.3.0/24");
    Ip4Address nextHop1 = Ip4Address.valueOf("5.6.7.8");
    RouteEntry routeEntry1 = new RouteEntry(prefix1, nextHop1);

    Ip4Prefix prefix2 = Ip4Prefix.valueOf("1.2.3.0/24");
    Ip4Address nextHop2 = Ip4Address.valueOf("5.6.7.8");
    RouteEntry routeEntry2 = new RouteEntry(prefix2, nextHop2);

    assertThat(routeEntry1, is(routeEntry2));

    Ip6Prefix prefix3 = Ip6Prefix.valueOf("1000::/64");
    Ip6Address nextHop3 = Ip6Address.valueOf("2000::2");
    RouteEntry routeEntry3 = new RouteEntry(prefix3, nextHop3);

    Ip6Prefix prefix4 = Ip6Prefix.valueOf("1000::/64");
    Ip6Address nextHop4 = Ip6Address.valueOf("2000::2");
    RouteEntry routeEntry4 = new RouteEntry(prefix4, nextHop4);

    assertThat(routeEntry3, is(routeEntry4));
}
 
Example #3
Source File: RouteEntryTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests object string representation.
 */
@Test
public void testToString() {
    Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24");
    Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8");
    RouteEntry routeEntry = new RouteEntry(prefix, nextHop);

    assertThat(routeEntry.toString(),
               is("RouteEntry{prefix=1.2.3.0/24, nextHop=5.6.7.8}"));

    Ip6Prefix prefix6 = Ip6Prefix.valueOf("1000::/64");
    Ip6Address nextHop6 = Ip6Address.valueOf("2000::1");
    RouteEntry routeEntry6 = new RouteEntry(prefix6, nextHop6);

    assertThat(routeEntry6.toString(),
               is("RouteEntry{prefix=1000::/64, nextHop=2000::1}"));
}
 
Example #4
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a routing flow rule that matches on the given IPv6 prefix and
 * executes the given group ID (created before).
 *
 * @param deviceId  the device where flow rule will be installed
 * @param ip6Prefix the IPv6 prefix
 * @param groupId   the group ID
 * @return a flow rule
 */
private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix,
                                   int groupId) {

    // TODO EXERCISE 3
    // Modify P4Runtime entity names to match content of P4Info file (look
    // for the fully qualified name of tables, match fields, and actions.
    // ---- START SOLUTION ----
    final String tableId = "MODIFY ME";
    final PiCriterion match = PiCriterion.builder()
            .matchLpm(
                    PiMatchFieldId.of("MODIFY ME"),
                    ip6Prefix.address().toOctets(),
                    ip6Prefix.prefixLength())
            .build();

    final PiTableAction action = PiActionProfileGroupId.of(groupId);
    // ---- END SOLUTION ----

    return Utils.buildFlowRule(
            deviceId, appId, tableId, match, action);
}
 
Example #5
Source File: Ipv6RoutingComponent.java    From ngsdn-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a routing flow rule that matches on the given IPv6 prefix and
 * executes the given group ID (created before).
 *
 * @param deviceId  the device where flow rule will be installed
 * @param ip6Prefix the IPv6 prefix
 * @param groupId   the group ID
 * @return a flow rule
 */
private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix,
                                   int groupId) {

    final String tableId = "IngressPipeImpl.routing_v6_table";
    final PiCriterion match = PiCriterion.builder()
            .matchLpm(
                    PiMatchFieldId.of("hdr.ipv6.dst_addr"),
                    ip6Prefix.address().toOctets(),
                    ip6Prefix.prefixLength())
            .build();

    final PiTableAction action = PiActionProfileGroupId.of(groupId);

    return Utils.buildFlowRule(
            deviceId, appId, tableId, match, action);
}
 
Example #6
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a routing flow rule that matches on the given IPv6 prefix and
 * executes the given group ID (created before).
 *
 * @param deviceId  the device where flow rule will be installed
 * @param ip6Prefix the IPv6 prefix
 * @param groupId   the group ID
 * @return a flow rule
 */
private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix,
                                   int groupId) {

    // TODO EXERCISE 3
    // Modify P4Runtime entity names to match content of P4Info file (look
    // for the fully qualified name of tables, match fields, and actions.
    // ---- START SOLUTION ----
    final String tableId = "IngressPipeImpl.l3_table";
    final PiCriterion match = PiCriterion.builder()
            .matchLpm(
                    PiMatchFieldId.of("hdr.ipv6.dst_addr"),
                    ip6Prefix.address().toOctets(),
                    ip6Prefix.prefixLength())
            .build();

    final PiTableAction action = PiActionProfileGroupId.of(groupId);
    // ---- END SOLUTION ----

    return Utils.buildFlowRule(
            deviceId, appId, tableId, match, action);
}
 
Example #7
Source File: Ipv6RoutingComponent.java    From ngsdn-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Insert routing rules on the given spine switch, matching on leaf
 * interface subnets and forwarding packets to the corresponding leaf.
 *
 * @param spineId the spine device ID
 */
private void setUpSpineRoutes(DeviceId spineId) {

    log.info("Adding up spine routes on {}...", spineId);

    for (Device device : deviceService.getDevices()) {

        if (isSpine(device.id())) {
            // We only need routes to leaf switches. Ignore spines.
            continue;
        }

        final DeviceId leafId = device.id();
        final MacAddress leafMac = getMyStationMac(leafId);
        final Set<Ip6Prefix> subnetsToRoute = getInterfaceIpv6Prefixes(leafId);

        // Create a group with only one member.
        int groupId = macToGroupId(leafMac);

        GroupDescription group = createNextHopGroup(
                groupId, Collections.singleton(leafMac), spineId);

        List<FlowRule> flowRules = subnetsToRoute.stream()
                .map(subnet -> createRoutingRule(spineId, subnet, groupId))
                .collect(Collectors.toList());

        insertInOrder(group, flowRules);
    }
}
 
Example #8
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Insert routing rules on the given spine switch, matching on leaf
 * interface subnets and forwarding packets to the corresponding leaf.
 *
 * @param spineId the spine device ID
 */
private void setUpSpineRoutes(DeviceId spineId) {

    log.info("Adding up spine routes on {}...", spineId);

    for (Device device : deviceService.getDevices()) {

        if (isSpine(device.id())) {
            // We only need routes to leaf switches. Ignore spines.
            continue;
        }

        final DeviceId leafId = device.id();
        final MacAddress leafMac = getMyStationMac(leafId);
        final Set<Ip6Prefix> subnetsToRoute = getInterfaceIpv6Prefixes(leafId);

        // Since we're here, we also add a route for SRv6, to forward
        // packets with IPv6 dst the SID of a leaf switch.
        final Ip6Address leafSid = getDeviceSid(leafId);
        subnetsToRoute.add(Ip6Prefix.valueOf(leafSid, 128));

        // Create a group with only one member.
        int groupId = macToGroupId(leafMac);

        GroupDescription group = createNextHopGroup(
                groupId, Collections.singleton(leafMac), spineId);

        List<FlowRule> flowRules = subnetsToRoute.stream()
                .map(subnet -> createRoutingRule(spineId, subnet, groupId))
                .collect(Collectors.toList());

        insertInOrder(group, flowRules);
    }
}
 
Example #9
Source File: RouteEntryTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests getting the fields of a route entry.
 */
@Test
public void testGetFields() {
    Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24");
    Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8");
    RouteEntry routeEntry = new RouteEntry(prefix, nextHop);
    assertThat(routeEntry.prefix(), is(prefix));
    assertThat(routeEntry.nextHop(), is(nextHop));

    Ip6Prefix prefix6 = Ip6Prefix.valueOf("1000::/64");
    Ip6Address nextHop6 = Ip6Address.valueOf("2000::1");
    RouteEntry routeEntry6 = new RouteEntry(prefix6, nextHop6);
    assertThat(routeEntry6.prefix(), is(prefix6));
    assertThat(routeEntry6.nextHop(), is(nextHop6));
}
 
Example #10
Source File: RouteEntryTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests invalid class constructor for null IPv6 next-hop.
 */
@Test(expected = NullPointerException.class)
public void testInvalidConstructorNullIpv6NextHop() {
    Ip6Prefix prefix = Ip6Prefix.valueOf("1000::/64");
    Ip6Address nextHop = null;

    new RouteEntry(prefix, nextHop);
}
 
Example #11
Source File: RouteEntryTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests invalid class constructor for null IPv6 prefix.
 */
@Test(expected = NullPointerException.class)
public void testInvalidConstructorNullIpv6Prefix() {
    Ip6Prefix prefix = null;
    Ip6Address nextHop = Ip6Address.valueOf("2000::1");

    new RouteEntry(prefix, nextHop);
}
 
Example #12
Source File: BgpUpdate.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a message that contains encoded IPv6 network prefixes.
 * <p>
 * The IPv6 prefixes are encoded in the form:
 * <Length, Prefix> where Length is the length in bits of the IPv6 prefix,
 * and Prefix is the IPv6 prefix (padded with trailing bits to the end
 * of an octet).
 *
 * @param totalLength the total length of the data to parse
 * @param message the message with data to parse
 * @return a collection of parsed IPv6 network prefixes
 * @throws BgpMessage.BgpParseException
 */
private static Collection<Ip6Prefix> parsePackedIp6Prefixes(
                                            int totalLength,
                                            ChannelBuffer message)
    throws BgpMessage.BgpParseException {
    Collection<Ip6Prefix> result = new ArrayList<>();

    if (totalLength == 0) {
        return result;
    }

    // Parse the data
    byte[] buffer = new byte[Ip6Address.BYTE_LENGTH];
    int dataEnd = message.readerIndex() + totalLength;
    while (message.readerIndex() < dataEnd) {
        int prefixBitlen = message.readUnsignedByte();
        int prefixBytelen = (prefixBitlen + 7) / 8;     // Round-up
        if (message.readerIndex() + prefixBytelen > dataEnd) {
            String errorMsg = "Malformed Network Prefixes";
            throw new BgpMessage.BgpParseException(errorMsg);
        }

        message.readBytes(buffer, 0, prefixBytelen);
        Ip6Prefix prefix = Ip6Prefix.valueOf(Ip6Address.valueOf(buffer),
                                             prefixBitlen);
        result.add(prefix);
    }

    return result;
}
 
Example #13
Source File: RouteEntryTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests non-equality of {@link RouteEntry}.
 */
@Test
public void testNonEquality() {
    Ip4Prefix prefix1 = Ip4Prefix.valueOf("1.2.3.0/24");
    Ip4Address nextHop1 = Ip4Address.valueOf("5.6.7.8");
    RouteEntry routeEntry1 = new RouteEntry(prefix1, nextHop1);

    Ip4Prefix prefix2 = Ip4Prefix.valueOf("1.2.3.0/25");      // Different
    Ip4Address nextHop2 = Ip4Address.valueOf("5.6.7.8");
    RouteEntry routeEntry2 = new RouteEntry(prefix2, nextHop2);

    Ip4Prefix prefix3 = Ip4Prefix.valueOf("1.2.3.0/24");
    Ip4Address nextHop3 = Ip4Address.valueOf("5.6.7.9");      // Different
    RouteEntry routeEntry3 = new RouteEntry(prefix3, nextHop3);

    assertThat(routeEntry1, Matchers.is(Matchers.not(routeEntry2)));
    assertThat(routeEntry1, Matchers.is(Matchers.not(routeEntry3)));

    Ip6Prefix prefix4 = Ip6Prefix.valueOf("1000::/64");
    Ip6Address nextHop4 = Ip6Address.valueOf("2000::1");
    RouteEntry routeEntry4 = new RouteEntry(prefix4, nextHop4);

    Ip6Prefix prefix5 = Ip6Prefix.valueOf("1000::/65");
    Ip6Address nextHop5 = Ip6Address.valueOf("2000::1");
    RouteEntry routeEntry5 = new RouteEntry(prefix5, nextHop5);

    Ip6Prefix prefix6 = Ip6Prefix.valueOf("1000::/64");
    Ip6Address nextHop6 = Ip6Address.valueOf("2000::2");
    RouteEntry routeEntry6 = new RouteEntry(prefix6, nextHop6);

    assertThat(routeEntry4, Matchers.is(Matchers.not(routeEntry5)));
    assertThat(routeEntry4, Matchers.is(Matchers.not(routeEntry6)));
}
 
Example #14
Source File: BgpSession.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a BGP route. The route can be either IPv4 or IPv6.
 *
 * @param bgpRouteEntry the BGP route entry to use
 */
void addBgpRoute(BgpRouteEntry bgpRouteEntry) {
    if (bgpRouteEntry.isIp4()) {
        // IPv4 route
        Ip4Prefix ip4Prefix = bgpRouteEntry.prefix().getIp4Prefix();
        bgpRibIn4.put(ip4Prefix, bgpRouteEntry);
    } else {
        // IPv6 route
        Ip6Prefix ip6Prefix = bgpRouteEntry.prefix().getIp6Prefix();
        bgpRibIn6.put(ip6Prefix, bgpRouteEntry);
    }
}
 
Example #15
Source File: BgpSession.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Finds a BGP routing entry for a prefix in the BGP RIB-IN. The prefix
 * can be either IPv4 or IPv6.
 *
 * @param prefix the IP prefix of the route to search for
 * @return the BGP routing entry if found, otherwise null
 */
public BgpRouteEntry findBgpRoute(IpPrefix prefix) {
    if (prefix.isIp4()) {
        // IPv4 prefix
        Ip4Prefix ip4Prefix = prefix.getIp4Prefix();
        return bgpRibIn4.get(ip4Prefix);
    }

    // IPv6 prefix
    Ip6Prefix ip6Prefix = prefix.getIp6Prefix();
    return bgpRibIn6.get(ip6Prefix);
}
 
Example #16
Source File: Ipv6RoutingComponent.java    From ngsdn-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Insert routing rules on the given leaf switch, matching on interface
 * subnets associated to other leaves and forwarding packets the spines
 * using ECMP.
 *
 * @param leafId the leaf device ID
 */
private void setUpLeafRoutes(DeviceId leafId) {
    log.info("Setting up leaf routes: {}", leafId);

    // Get the set of subnets (interface IPv6 prefixes) associated to other
    // leafs but not this one.
    Set<Ip6Prefix> subnetsToRouteViaSpines = stream(deviceService.getDevices())
            .map(Device::id)
            .filter(this::isLeaf)
            .filter(deviceId -> !deviceId.equals(leafId))
            .map(this::getInterfaceIpv6Prefixes)
            .flatMap(Collection::stream)
            .collect(Collectors.toSet());

    // Get myStationMac address of all spines.
    Set<MacAddress> spineMacs = stream(deviceService.getDevices())
            .map(Device::id)
            .filter(this::isSpine)
            .map(this::getMyStationMac)
            .collect(Collectors.toSet());

    // Create an ECMP group to distribute traffic across all spines.
    final int groupId = DEFAULT_ECMP_GROUP_ID;
    final GroupDescription ecmpGroup = createNextHopGroup(
            groupId, spineMacs, leafId);

    // Generate a flow rule for each subnet pointing to the ECMP group.
    List<FlowRule> flowRules = subnetsToRouteViaSpines.stream()
            .map(subnet -> createRoutingRule(leafId, subnet, groupId))
            .collect(Collectors.toList());

    insertInOrder(ecmpGroup, flowRules);
}
 
Example #17
Source File: SimpleFabricRouting.java    From onos with Apache License 2.0 5 votes vote down vote up
private FlowRule generateLocalSubnetIpBctFlowRule(DeviceId deviceId, IpPrefix prefix, FabricNetwork fabricNetwork) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    IpPrefix bctPrefix;
    if (prefix.isIp4()) {
        bctPrefix = Ip4Prefix.valueOf(prefix.getIp4Prefix().address().toInt() |
                                          ~Ip4Address.makeMaskPrefix(prefix.prefixLength()).toInt(),
                                      Ip4Address.BIT_LENGTH);
        selector.matchEthType(Ethernet.TYPE_IPV4);
        selector.matchIPDst(bctPrefix);
    } else {
        byte[] p = prefix.getIp6Prefix().address().toOctets();
        byte[] m = Ip6Address.makeMaskPrefix(prefix.prefixLength()).toOctets();
        for (int i = 0; i < p.length; i++) {
             p[i] |= ~m[i];
        }
        bctPrefix = Ip6Prefix.valueOf(p, Ip6Address.BIT_LENGTH);
        selector.matchEthType(Ethernet.TYPE_IPV6);
        selector.matchIPv6Dst(bctPrefix);
    }
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    Set<ConnectPoint> newEgressPoints = new HashSet<>();
    for (Interface iface : fabricNetwork.interfaces()) {
        if (iface.connectPoint().deviceId().equals(deviceId)) {
            treatment.setOutput(iface.connectPoint().port());
        }
    }
    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withPriority(reactivePriority(true, true, bctPrefix.prefixLength()))
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .fromApp(appId)
            .makePermanent()
            .forTable(0).build();
    return rule;
}
 
Example #18
Source File: Ip6PrefixSerializer.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output,
        Ip6Prefix object) {
    byte[] octs = object.address().toOctets();
    // It is always Ip6Address.BYTE_LENGTH
    output.writeInt(octs.length);
    output.writeBytes(octs);
    output.writeInt(object.prefixLength());
}
 
Example #19
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the set of interface IPv6 subnets (prefixes) configured for the
 * given device.
 *
 * @param deviceId the device ID
 * @return set of IPv6 prefixes
 */
private Set<Ip6Prefix> getInterfaceIpv6Prefixes(DeviceId deviceId) {
    return interfaceService.getInterfaces().stream()
            .filter(iface -> iface.connectPoint().deviceId().equals(deviceId))
            .map(Interface::ipAddressesList)
            .flatMap(Collection::stream)
            .map(InterfaceIpAddress::subnetAddress)
            .filter(IpPrefix::isIp6)
            .map(IpPrefix::getIp6Prefix)
            .collect(Collectors.toSet());
}
 
Example #20
Source File: Ip6PrefixSerializer.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Ip6Prefix read(Kryo kryo, Input input,
        Class<Ip6Prefix> type) {
    int octLen = input.readInt();
    checkArgument(octLen <= Ip6Address.BYTE_LENGTH);
    byte[] octs = new byte[octLen];
    input.readBytes(octs);
    int prefLen = input.readInt();
    return Ip6Prefix.valueOf(octs, prefLen);
}
 
Example #21
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Insert routing rules on the given spine switch, matching on leaf
 * interface subnets and forwarding packets to the corresponding leaf.
 *
 * @param spineId the spine device ID
 */
private void setUpSpineRoutes(DeviceId spineId) {

    log.info("Adding up spine routes on {}...", spineId);

    for (Device device : deviceService.getDevices()) {

        if (isSpine(device.id())) {
            // We only need routes to leaf switches. Ignore spines.
            continue;
        }

        final DeviceId leafId = device.id();
        final MacAddress leafMac = getMyStationMac(leafId);
        final Set<Ip6Prefix> subnetsToRoute = getInterfaceIpv6Prefixes(leafId);

        // Since we're here, we also add a route for SRv6, to forward
        // packets with IPv6 dst the SID of a leaf switch.
        final Ip6Address leafSid = getDeviceSid(leafId);
        subnetsToRoute.add(Ip6Prefix.valueOf(leafSid, 128));

        // Create a group with only one member.
        int groupId = macToGroupId(leafMac);

        GroupDescription group = createNextHopGroup(
                groupId, Collections.singleton(leafMac), spineId);

        List<FlowRule> flowRules = subnetsToRoute.stream()
                .map(subnet -> createRoutingRule(spineId, subnet, groupId))
                .collect(Collectors.toList());

        insertInOrder(group, flowRules);
    }
}
 
Example #22
Source File: Ipv6RoutingComponent.java    From ngsdn-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the set of interface IPv6 subnets (prefixes) configured for the
 * given device.
 *
 * @param deviceId the device ID
 * @return set of IPv6 prefixes
 */
private Set<Ip6Prefix> getInterfaceIpv6Prefixes(DeviceId deviceId) {
    return interfaceService.getInterfaces().stream()
            .filter(iface -> iface.connectPoint().deviceId().equals(deviceId))
            .map(Interface::ipAddressesList)
            .flatMap(Collection::stream)
            .map(InterfaceIpAddress::subnetAddress)
            .filter(IpPrefix::isIp6)
            .map(IpPrefix::getIp6Prefix)
            .collect(Collectors.toSet());
}
 
Example #23
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the set of interface IPv6 subnets (prefixes) configured for the
 * given device.
 *
 * @param deviceId the device ID
 * @return set of IPv6 prefixes
 */
private Set<Ip6Prefix> getInterfaceIpv6Prefixes(DeviceId deviceId) {
    return interfaceService.getInterfaces().stream()
            .filter(iface -> iface.connectPoint().deviceId().equals(deviceId))
            .map(Interface::ipAddressesList)
            .flatMap(Collection::stream)
            .map(InterfaceIpAddress::subnetAddress)
            .filter(IpPrefix::isIp6)
            .map(IpPrefix::getIp6Prefix)
            .collect(Collectors.toSet());
}
 
Example #24
Source File: KryoSerializerTest.java    From onos with Apache License 2.0 4 votes vote down vote up
@Test
public void testIp6Prefix() {
    testSerializedEquals(Ip6Prefix.valueOf("1111:2222::/120"));
}
 
Example #25
Source File: AclRule.java    From onos with Apache License 2.0 4 votes vote down vote up
public Ip6Prefix dstIp6() {
    return dstIp6;
}
 
Example #26
Source File: AclRule.java    From onos with Apache License 2.0 4 votes vote down vote up
public Ip6Prefix srcIp6() {
    return srcIp6;
}
 
Example #27
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 4 votes vote down vote up
/**
 * Insert routing rules on the given leaf switch, matching on interface
 * subnets associated to other leaves and forwarding packets the spines
 * using ECMP.
 *
 * @param leafId the leaf device ID
 */
private void setUpLeafRoutes(DeviceId leafId) {
    log.info("Setting up leaf routes: {}", leafId);

    // Get the set of subnets (interface IPv6 prefixes) associated to other
    // leafs but not this one.
    Set<Ip6Prefix> subnetsToRouteViaSpines = stream(deviceService.getDevices())
            .map(Device::id)
            .filter(this::isLeaf)
            .filter(deviceId -> !deviceId.equals(leafId))
            .map(this::getInterfaceIpv6Prefixes)
            .flatMap(Collection::stream)
            .collect(Collectors.toSet());

    // Get myStationMac address of all spines.
    Set<MacAddress> spineMacs = stream(deviceService.getDevices())
            .map(Device::id)
            .filter(this::isSpine)
            .map(this::getMyStationMac)
            .collect(Collectors.toSet());

    // Create an ECMP group to distribute traffic across all spines.
    final int groupId = DEFAULT_ECMP_GROUP_ID;
    final GroupDescription ecmpGroup = createNextHopGroup(
            groupId, spineMacs, leafId);

    // Generate a flow rule for each subnet pointing to the ECMP group.
    List<FlowRule> flowRules = subnetsToRouteViaSpines.stream()
            .map(subnet -> createRoutingRule(leafId, subnet, groupId))
            .collect(Collectors.toList());

    insertInOrder(ecmpGroup, flowRules);

    // Since we're here, we also add a route for SRv6, to forward
    // packets with IPv6 dst the SID of a spine switch, in this case using a
    // single-member group.
    stream(deviceService.getDevices())
            .map(Device::id)
            .filter(this::isSpine)
            .forEach(spineId -> {
                MacAddress spineMac = getMyStationMac(spineId);
                Ip6Address spineSid = getDeviceSid(spineId);
                int spineGroupId = macToGroupId(spineMac);
                GroupDescription group = createNextHopGroup(
                        spineGroupId, Collections.singleton(spineMac), leafId);
                FlowRule routingRule = createRoutingRule(
                        leafId, Ip6Prefix.valueOf(spineSid, 128),
                        spineGroupId);
                insertInOrder(group, Collections.singleton(routingRule));
            });
}
 
Example #28
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 4 votes vote down vote up
/**
 * Insert routing rules on the given leaf switch, matching on interface
 * subnets associated to other leaves and forwarding packets the spines
 * using ECMP.
 *
 * @param leafId the leaf device ID
 */
private void setUpLeafRoutes(DeviceId leafId) {
    log.info("Setting up leaf routes: {}", leafId);

    // Get the set of subnets (interface IPv6 prefixes) associated to other
    // leafs but not this one.
    Set<Ip6Prefix> subnetsToRouteViaSpines = stream(deviceService.getDevices())
            .map(Device::id)
            .filter(this::isLeaf)
            .filter(deviceId -> !deviceId.equals(leafId))
            .map(this::getInterfaceIpv6Prefixes)
            .flatMap(Collection::stream)
            .collect(Collectors.toSet());

    // Get myStationMac address of all spines.
    Set<MacAddress> spineMacs = stream(deviceService.getDevices())
            .map(Device::id)
            .filter(this::isSpine)
            .map(this::getMyStationMac)
            .collect(Collectors.toSet());

    // Create an ECMP group to distribute traffic across all spines.
    final int groupId = DEFAULT_ECMP_GROUP_ID;
    final GroupDescription ecmpGroup = createNextHopGroup(
            groupId, spineMacs, leafId);

    // Generate a flow rule for each subnet pointing to the ECMP group.
    List<FlowRule> flowRules = subnetsToRouteViaSpines.stream()
            .map(subnet -> createRoutingRule(leafId, subnet, groupId))
            .collect(Collectors.toList());

    insertInOrder(ecmpGroup, flowRules);

    // Since we're here, we also add a route for SRv6, to forward
    // packets with IPv6 dst the SID of a spine switch, in this case using a
    // single-member group.
    stream(deviceService.getDevices())
            .map(Device::id)
            .filter(this::isSpine)
            .forEach(spineId -> {
                MacAddress spineMac = getMyStationMac(spineId);
                Ip6Address spineSid = getDeviceSid(spineId);
                int spineGroupId = macToGroupId(spineMac);
                GroupDescription group = createNextHopGroup(
                        spineGroupId, Collections.singleton(spineMac), leafId);
                FlowRule routingRule = createRoutingRule(
                        leafId, Ip6Prefix.valueOf(spineSid, 128),
                        spineGroupId);
                insertInOrder(group, Collections.singleton(routingRule));
            });
}
 
Example #29
Source File: BgpSession.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Removes an IPv6 BGP route for a prefix.
 *
 * @param prefix the prefix to use
 * @return true if the route was found and removed, otherwise false
 */
boolean removeBgpRoute(Ip6Prefix prefix) {
    return (bgpRibIn6.remove(prefix) != null);
}
 
Example #30
Source File: BgpSession.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Finds an IPv6 BGP routing entry for a prefix in the IPv6 BGP RIB-IN.
 *
 * @param prefix the IPv6 prefix of the route to search for
 * @return the IPv6 BGP routing entry if found, otherwise null
 */
public BgpRouteEntry findBgpRoute(Ip6Prefix prefix) {
    return bgpRibIn6.get(prefix);
}