Java Code Examples for org.onlab.packet.Ip6Address#valueOf()

The following examples show how to use org.onlab.packet.Ip6Address#valueOf() . 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: IpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Processes incoming IPv6 packets.
 *
 * If it is an IPv6 packet for known host, then forward it to the host.
 * If it is an IPv6 packet for unknown host in subnet, then send an NDP request
 * to the subnet.
 *
 * @param pkt incoming packet
 * @param connectPoint the target device
 */
public void processPacketIn(IPv6 pkt, ConnectPoint connectPoint) {

    DeviceId deviceId = connectPoint.deviceId();
    Ip6Address destinationAddress = Ip6Address.valueOf(pkt.getDestinationAddress());

    // IPv6 packet for know hosts
    if (!srManager.hostService.getHostsByIp(destinationAddress).isEmpty()) {
        forwardPackets(deviceId, destinationAddress);

        // IPv6 packet for unknown host in one of the configured subnets of the router
    } else if (config.inSameSubnet(deviceId, destinationAddress)) {
        srManager.icmpHandler.sendNdpRequest(deviceId, destinationAddress, connectPoint);

        // IPv6 packets for unknown host
    } else {
        log.debug("IPv6 packet for unknown host {} which is not in the subnet",
                  destinationAddress);
    }
}
 
Example 2
Source File: BgpAttrRouterIdV6.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Reads the IPv6 Router-ID.
 *
 * @param cb ChannelBuffer
 * @param sType TLV type
 * @return object of BgpAttrRouterIdV6
 * @throws BgpParseException while parsing BgpAttrRouterIdV6
 */
public static BgpAttrRouterIdV6 read(ChannelBuffer cb, short sType)
        throws BgpParseException {
    byte[] ipBytes;
    Ip6Address ip6RouterId;

    short lsAttrLength = cb.readShort();

    if ((lsAttrLength != 16) || (cb.readableBytes() < lsAttrLength)) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
                               BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
                               lsAttrLength);
    }

    ipBytes = new byte[lsAttrLength];
    cb.readBytes(ipBytes);
    ip6RouterId = Ip6Address.valueOf(ipBytes);
    return BgpAttrRouterIdV6.of(ip6RouterId, sType);
}
 
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: PIMAddrUnicast.java    From onos with Apache License 2.0 6 votes vote down vote up
public PIMAddrUnicast deserialize(ByteBuffer bb) throws DeserializationException {

        // Assume IPv4 for check length until we read the encoded family.
        checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_UNICAST_IPV4_BYTE_LENGTH);
        this.family = bb.get();

        // If we have IPv6 we need to ensure we have adequate buffer space.
        if (this.family != PIM.ADDRESS_FAMILY_IP4 && this.family != PIM.ADDRESS_FAMILY_IP6) {
            throw new DeserializationException("Invalid address family: " + this.family);
        } else if (this.family == PIM.ADDRESS_FAMILY_IP6) {
            // Subtract -1 from ENC_UNICAST_IPv6 BYTE_LENGTH because we read one byte for family previously.
            checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_UNICAST_IPV6_BYTE_LENGTH - 1);
        }

        this.encType = bb.get();
        if (this.family == PIM.ADDRESS_FAMILY_IP4) {
            this.addr = IpAddress.valueOf(bb.getInt());
        } else if (this.family == PIM.ADDRESS_FAMILY_IP6) {
            this.addr = Ip6Address.valueOf(bb.array(), 2);
        }
        return this;
    }
 
Example 5
Source File: PIMAddrGroup.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Deserialze from a ByteBuffer.
 *
 * @param bb the ByteBuffer
 * @return an encoded PIM group address
 * @throws DeserializationException if unable to deserialize the packet data
 */
public PIMAddrGroup deserialize(ByteBuffer bb) throws DeserializationException {

    /*
     * We need to verify that we have enough buffer space.  First we'll assume that
     * we are decoding an IPv4 address.  After we read the first by (address family),
     * we'll determine if we actually need more buffer space for an IPv6 address.
     */
    checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_GROUP_IPV4_BYTE_LENGTH);

    this.family = bb.get();
    if (family != PIM.ADDRESS_FAMILY_IP4 && family != PIM.ADDRESS_FAMILY_IP6) {
        throw new DeserializationException("Illegal IP version number: " + family + "\n");
    } else if (family == PIM.ADDRESS_FAMILY_IP6) {

        // Check for one less by since we have already read the first byte of the packet.
        checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_GROUP_IPV6_BYTE_LENGTH - 1);
    }

    this.encType = bb.get();
    this.reserved = bb.get();
    if ((this.reserved & 0x80) != 0) {
        this.bBit = true;
    }
    if ((this.reserved & 0x01) != 0) {
        this.zBit = true;
    }
    // Remove the z and b bits from reserved
    this.reserved |= 0x7d;

    this.masklen = bb.get();
    if (this.family == PIM.ADDRESS_FAMILY_IP4) {
        this.addr = IpAddress.valueOf(bb.getInt());
    } else if (this.family == PIM.ADDRESS_FAMILY_IP6) {
        this.addr = Ip6Address.valueOf(bb.array(), 2);
    }
    return this;
}
 
Example 6
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a forwarding objective to punt all IP packets, destined to the
 * router's port IP addresses, to the controller. Note that the input
 * port should not be matched on, as these packets can come from any input.
 * Furthermore, these are applied only by the master instance.
 *
 * @param deviceId the switch dpid for the router
 */
void populateIpPunts(DeviceId deviceId) {
    Ip4Address routerIpv4, pairRouterIpv4 = null;
    Ip6Address routerIpv6, routerLinkLocalIpv6, pairRouterIpv6 = null;
    try {
        routerIpv4 = config.getRouterIpv4(deviceId);
        routerIpv6 = config.getRouterIpv6(deviceId);
        routerLinkLocalIpv6 = Ip6Address.valueOf(
                IPv6.getLinkLocalAddress(config.getDeviceMac(deviceId).toBytes()));

        if (config.isPairedEdge(deviceId)) {
            pairRouterIpv4 = config.getRouterIpv4(config.getPairDeviceId(deviceId));
            pairRouterIpv6 = config.getRouterIpv6(config.getPairDeviceId(deviceId));
        }
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Aborting populateIpPunts.");
        return;
    }

    if (!srManager.mastershipService.isLocalMaster(deviceId)) {
        log.debug("Not installing port-IP punts - not the master for dev:{} ",
                  deviceId);
        return;
    }
    Set<IpAddress> allIps = new HashSet<>(config.getPortIPs(deviceId));
    allIps.add(routerIpv4);
    if (routerIpv6 != null) {
        allIps.add(routerIpv6);
        allIps.add(routerLinkLocalIpv6);
    }
    if (pairRouterIpv4 != null) {
        allIps.add(pairRouterIpv4);
    }
    if (pairRouterIpv6 != null) {
        allIps.add(pairRouterIpv6);
    }
    for (IpAddress ipaddr : allIps) {
        populateSingleIpPunts(deviceId, ipaddr);
    }
}
 
Example 7
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 8
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 9
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 10
Source File: PiCriterionTranslatorsTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Test
public void testIPv6NDTargetAddressCriterion() throws Exception {
    Ip6Address targetAddress = Ip6Address.valueOf("2001:A304:6101:1::E0:F726:4E58");
    int bitWidth = targetAddress.toOctets().length * 8;

    IPv6NDTargetAddressCriterion criterion = (IPv6NDTargetAddressCriterion) Criteria
            .matchIPv6NDTargetAddress(targetAddress);

    PiExactFieldMatch exactMatch = (PiExactFieldMatch) translateCriterion(criterion, fieldId, EXACT, bitWidth);

    assertThat(exactMatch.value().asArray(), is(criterion.targetAddress().toOctets()));
}
 
Example 11
Source File: InstructionCodecTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the encoding of mod IPv6 src instructions.
 */
@Test
public void modIPv6SrcInstructionTest() {
    final Ip6Address ip = Ip6Address.valueOf("1111::2222");
    final L3ModificationInstruction.ModIPInstruction instruction =
            (L3ModificationInstruction.ModIPInstruction)
                    Instructions.modL3IPv6Src(ip);
    final ObjectNode instructionJson =
            instructionCodec.encode(instruction, context);
    assertThat(instructionJson, matchesInstruction(instruction));
}
 
Example 12
Source File: Dhcp6IaAddressOption.java    From onos with Apache License 2.0 5 votes vote down vote up
public static Deserializer<Dhcp6Option> deserializer() {
    return (data, offset, length) -> {
        Dhcp6IaAddressOption iaAddressOption = new Dhcp6IaAddressOption();
        Dhcp6Option dhcp6Option =
                Dhcp6Option.deserializer().deserialize(data, offset, length);
        iaAddressOption.setPayload(dhcp6Option.getPayload());
        if (dhcp6Option.getLength() < DEFAULT_LEN) {
            throw new DeserializationException("Invalid length of IA address option");
        }
        ByteBuffer bb = ByteBuffer.wrap(dhcp6Option.getData());
        byte[] ipv6Addr = new byte[16];
        bb.get(ipv6Addr);
        iaAddressOption.ip6Address = Ip6Address.valueOf(ipv6Addr);
        iaAddressOption.preferredLifetime = bb.getInt();
        iaAddressOption.validLifetime = bb.getInt();

        // options length of IA Address option
        int optionsLen = dhcp6Option.getLength() - DEFAULT_LEN;
        if (optionsLen > 0) {
            byte[] optionsData = new byte[optionsLen];
            bb.get(optionsData);
            iaAddressOption.options =
                    Data.deserializer().deserialize(optionsData, 0, optionsLen);
        }
        return iaAddressOption;
    };
}
 
Example 13
Source File: IpHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Forwards IP packets in the buffer to the destination IP address.
 * It is called when the controller finds the destination MAC address
 * via NDP replies.
 *
 * @param deviceId the target device
 * @param destIpAddress the destination ip address
 */
public void forwardPackets(DeviceId deviceId, Ip6Address destIpAddress) {
    if (ipPacketQueue.get(destIpAddress) == null) {
        return;
    }
    for (IP ipPacket : ipPacketQueue.get(destIpAddress)) {
        if (ipPacket.getVersion() == ((byte) 6)) {
            IPv6 ipv6Packet = (IPv6) ipPacket;
            Ip6Address destAddress = Ip6Address.valueOf(ipv6Packet.getDestinationAddress());
            if (config.inSameSubnet(deviceId, destAddress)) {
                ipv6Packet.setHopLimit((byte) (ipv6Packet.getHopLimit() - 1));
                for (Host dest : srManager.hostService.getHostsByIp(destIpAddress)) {
                    Ethernet eth = new Ethernet();
                    eth.setDestinationMACAddress(dest.mac());
                    try {
                        eth.setSourceMACAddress(config.getDeviceMac(deviceId));
                    } catch (DeviceConfigNotFoundException e) {
                        log.warn(e.getMessage()
                                         + " Skipping forwardPackets for this destination.");
                        continue;
                    }
                    eth.setEtherType(Ethernet.TYPE_IPV6);
                    eth.setPayload(ipv6Packet);
                    forwardToHost(deviceId, eth, dest);
                    ipPacketQueue.get(destIpAddress).remove(ipPacket);
                }
                ipPacketQueue.get(destIpAddress).remove(ipPacket);
            }
        }
        ipPacketQueue.get(destIpAddress).remove(ipPacket);
    }
}
 
Example 14
Source File: Ip6AddressSerializer.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Ip6Address read(Kryo kryo, Input input, Class<Ip6Address> type) {
    final int octLen = input.readInt();
    checkArgument(octLen == Ip6Address.BYTE_LENGTH);
    byte[] octs = new byte[octLen];
    input.readBytes(octs);
    return Ip6Address.valueOf(octs);
}
 
Example 15
Source File: Dhcp6LeaseQueryOption.java    From onos with Apache License 2.0 4 votes vote down vote up
public static Deserializer<Dhcp6Option> deserializer() {
    return (data, offset, length) -> {
        Dhcp6Option dhcp6Option = Dhcp6Option.deserializer().deserialize(data, offset, length);
        Dhcp6LeaseQueryOption lQ6Option = new Dhcp6LeaseQueryOption(dhcp6Option);

        byte[] optionData = lQ6Option.getData();
        if (optionData.length >= DEFAULT_LEN) {
            ByteBuffer bb = ByteBuffer.wrap(optionData);
            // fetch the Query type - just pop the byte from the byte buffer for subsequent parsing...
            lQ6Option.queryType = bb.get();
            byte[] ipv6Addr = new byte[16];
            bb.get(ipv6Addr);
            lQ6Option.linkAddress = Ip6Address.valueOf(ipv6Addr);
            //int optionsLen = dhcp6Option.getLength() - 1 - 16; // query type (1) + link address (16)

            lQ6Option.options = Lists.newArrayList();

            while (bb.remaining() >= Dhcp6Option.DEFAULT_LEN) {
                Dhcp6Option option;
                ByteBuffer optByteBuffer = ByteBuffer.wrap(optionData,
                                                           bb.position(),
                                                           optionData.length - bb.position());
                short code = optByteBuffer.getShort();
                short len = optByteBuffer.getShort();
                int optLen = UNSIGNED_SHORT_MASK & len;
                byte[] subOptData = new byte[Dhcp6Option.DEFAULT_LEN + optLen];
                bb.get(subOptData);

                // TODO: put more sub-options?
                if (code == DHCP6.OptionCode.IAADDR.value()) {
                    option = Dhcp6IaAddressOption.deserializer()
                            .deserialize(subOptData, 0, subOptData.length);
                } else if (code == DHCP6.OptionCode.ORO.value()) {
                    option = Dhcp6Option.deserializer()
                                .deserialize(subOptData, 0, subOptData.length);
                } else {
                    option = Dhcp6Option.deserializer()
                            .deserialize(subOptData, 0, subOptData.length);
                }
                lQ6Option.options.add(option);
            }
        }
        return lQ6Option;
    };
}
 
Example 16
Source File: DecodeCriterionCodecHelper.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public Criterion decodeCriterion(ObjectNode json) {
    Ip6Address target = Ip6Address.valueOf(nullIsIllegal(json.get(CriterionCodec.TARGET_ADDRESS),
            CriterionCodec.TARGET_ADDRESS + MISSING_MEMBER_MESSAGE).asText());
    return Criteria.matchIPv6NDTargetAddress(target);
}
 
Example 17
Source File: HostManager.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void hostDetected(HostId hostId, HostDescription initialHostDescription, boolean replaceIps) {
    HostDescription hostDescription = initialHostDescription;
    checkNotNull(hostId, HOST_ID_NULL);
    checkValidity();
    hostDescription = validateHost(hostDescription, hostId);

    if (!allowDuplicateIps) {
        removeDuplicates(hostId, hostDescription);
    }

    BasicHostConfig cfg = networkConfigService.getConfig(hostId, BasicHostConfig.class);
    if (!isAllowed(cfg)) {
        log.warn("Host {} is not allowed to be added into the contol domain", hostId);
        return;
    }

    hostDescription = BasicHostOperator.combine(cfg, initialHostDescription);
    HostAnnotationConfig annoConfig = networkConfigService.getConfig(hostId, HostAnnotationConfig.class);
    if (annoConfig != null) {
        hostDescription = hostAnnotationOperator.combine(hostId, hostDescription, Optional.of(annoConfig));
    }

    if (!hostMoveTrackerEnabled) {
        store.createOrUpdateHost(provider().id(), hostId,
                hostDescription, replaceIps);
    } else if (!shouldBlock(hostId, hostDescription.locations())) {
        log.debug("Host move is allowed for host with Id: {} ", hostId);
        store.createOrUpdateHost(provider().id(), hostId,
                hostDescription, replaceIps);
    } else {
        log.info("Host move is NOT allowed for host with Id: {} , removing from host store ", hostId);
    }

    if (monitorHosts) {
        hostDescription.ipAddress().forEach(ip -> {
            monitor.addMonitoringFor(ip);
        });
    }

    // Greedy learning of IPv6 host. We have to disable the greedy
    // learning of configured hosts. Validate hosts each time will
    // overwrite the learnt information with the configured information.
    if (greedyLearningIpv6) {
        // Auto-generation of the IPv6 link local address
        // using the mac address
        Ip6Address targetIp6Address = Ip6Address.valueOf(
                getLinkLocalAddress(hostId.mac().toBytes())
        );
        // If we already know this guy we don't need to do other
        if (!hostDescription.ipAddress().contains(targetIp6Address)) {
            Host host = store.getHost(hostId);
            // Configured host, skip it.
            if (host != null && host.configured()) {
                return;
            }
            // Host does not exist in the store or the target is not known
            if ((host == null || !host.ipAddresses().contains(targetIp6Address))) {
                // Use DAD to probe if interface MAC is not specified
                MacAddress probeMac = interfaceService.getInterfacesByPort(hostDescription.location())
                        .stream().map(Interface::mac).findFirst().orElse(MacAddress.ONOS);
                Ip6Address probeIp = !probeMac.equals(MacAddress.ONOS) ?
                        Ip6Address.valueOf(getLinkLocalAddress(probeMac.toBytes())) :
                        Ip6Address.ZERO;
                // We send a probe using the monitoring service
                monitor.sendProbe(
                        hostDescription.location(),
                        targetIp6Address,
                        probeIp,
                        probeMac,
                        hostId.vlanId()
                );
            }
        }
    }
}
 
Example 18
Source File: IcmpHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Sends an ICMPv6 reply message.
 *
 * @param ethRequest the original ICMP request
 * @param outport the output port where the ICMP reply should be sent to
 */
private void sendIcmpv6Response(Ethernet ethRequest, ConnectPoint outport) {
    int destSid = -1;
    Ethernet ethReply = ICMP6.buildIcmp6Reply(ethRequest);
    IPv6 icmpRequestIpv6 = (IPv6) ethRequest.getPayload();
    IPv6 icmpReplyIpv6 = (IPv6) ethRequest.getPayload();
    // Source IP of the echo "reply"
    Ip6Address srcIpAddress = Ip6Address.valueOf(icmpRequestIpv6.getDestinationAddress());
    // Destination IP of the echo "reply"
    Ip6Address destIpAddress = Ip6Address.valueOf(icmpRequestIpv6.getSourceAddress());
    Optional<Ip6Address> linkLocalIp = getLinkLocalIp(outport);

    // Fast path if the echo request targets the link-local address of switch interface
    if (linkLocalIp.isPresent() && srcIpAddress.equals(linkLocalIp.get())) {
        sendPacketOut(outport, ethReply, destSid, destIpAddress, icmpReplyIpv6.getHopLimit());
        return;
    }

    // Get the available connect points
    Set<ConnectPoint> destConnectPoints = config.getConnectPointsForASubnetHost(destIpAddress);
    // Select a router
    Ip6Address destRouterAddress = selectRouterIp6Address(destIpAddress, outport, destConnectPoints);

    // Note: Source IP of the ICMP request doesn't belong to any configured subnet.
    //       The source might be an indirect host behind a router.
    //       Lookup the route store for the nexthop instead.
    if (destRouterAddress == null) {
        Optional<DeviceId> deviceId = srManager.routeService
                .longestPrefixLookup(destIpAddress).map(srManager::nextHopLocations)
                .flatMap(locations -> locations.stream().findFirst())
                .map(ConnectPoint::deviceId);
        if (deviceId.isPresent()) {
            try {
                destRouterAddress = config.getRouterIpv6(deviceId.get());
            } catch (DeviceConfigNotFoundException e) {
                log.warn("Device config for {} not found. Abort ICMPv6 processing", deviceId);
                return;
            }
        }
    }

    destSid = config.getIPv6SegmentId(destRouterAddress);
    if (destSid < 0) {
        log.warn("Failed to lookup SID of the switch that {} attaches to. " +
                "Unable to process ICMPv6 request.", destIpAddress);
        return;
    }
    sendPacketOut(outport, ethReply, destSid, destIpAddress, icmpReplyIpv6.getHopLimit());
}
 
Example 19
Source File: Srv6DeviceConfig.java    From onos-p4-tutorial with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the SRv6 segment ID (SID) of the switch.
 *
 * @return IP address of the router. Or null if not configured.
 */
public Ip6Address mySid() {
    String ip = get(MY_SID, null);
    return ip != null ? Ip6Address.valueOf(ip) : null;
}
 
Example 20
Source File: Srv6DeviceConfig.java    From onos-p4-tutorial with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the SRv6 segment ID (SID) of the switch.
 *
 * @return IP address of the router. Or null if not configured.
 */
public Ip6Address mySid() {
    String ip = get(MY_SID, null);
    return ip != null ? Ip6Address.valueOf(ip) : null;
}