org.onlab.packet.Ip6Address Java Examples

The following examples show how to use org.onlab.packet.Ip6Address. 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: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    IPv6 ipv6 = new IPv6();
    ipv6.setDestinationAddress(Ip6Address.valueOf("1000::1").toOctets());
    ipv6.setSourceAddress(IP2);
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC2)
            .setDestinationMACAddress(MacAddress.valueOf("00:00:00:00:00:01"))
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #2
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 #3
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    NeighborSolicitation ns = new NeighborSolicitation();
    ICMP6 icmp6 = new ICMP6();
    icmp6.setPayload(ns);
    IPv6 ipv6 = new IPv6();
    ipv6.setPayload(icmp6);
    ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1:ff00:0000").toOctets());
    ipv6.setSourceAddress(IP2);
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC2.toBytes())
            .setDestinationMACAddress(BCMAC2)
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #4
Source File: Redirect.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] serialize() {
    byte[] optionsData = null;
    if (this.options.hasOptions()) {
        optionsData = this.options.serialize();
    }

    int optionsLength = 0;
    if (optionsData != null) {
        optionsLength = optionsData.length;
    }

    final byte[] data = new byte[HEADER_LENGTH + optionsLength];
    final ByteBuffer bb = ByteBuffer.wrap(data);

    bb.putInt(0);
    bb.put(this.targetAddress, 0, Ip6Address.BYTE_LENGTH);
    bb.put(this.destinationAddress, 0, Ip6Address.BYTE_LENGTH);
    if (optionsData != null) {
        bb.put(optionsData);
    }

    return data;
}
 
Example #5
Source File: NeighborSolicitation.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Deserializer function for neighbor solicitation packets.
 *
 * @return deserializer function
 */
public static Deserializer<NeighborSolicitation> deserializer() {
    return (data, offset, length) -> {
        checkInput(data, offset, length, HEADER_LENGTH);

        NeighborSolicitation neighborSolicitation = new NeighborSolicitation();

        ByteBuffer bb = ByteBuffer.wrap(data, offset, length);

        bb.getInt();
        bb.get(neighborSolicitation.targetAddress, 0, Ip6Address.BYTE_LENGTH);

        if (bb.limit() - bb.position() > 0) {
            NeighborDiscoveryOptions options = NeighborDiscoveryOptions.deserializer()
                    .deserialize(data, bb.position(), bb.limit() - bb.position());

            for (NeighborDiscoveryOptions.Option option : options.options()) {
                neighborSolicitation.addOption(option.type(), option.data());
            }
        }

        return neighborSolicitation;
    };
}
 
Example #6
Source File: RouteAttributeGateway.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Encode the RouteAttributeGateway contents into the ChannelBuffer.
 *
 * @param cb channelbuffer to be filled in
 */
@Override
public void encode(ChannelBuffer cb) {

    super.encode(cb);

    ChannelBuffer buffer =  ChannelBuffers.copiedBuffer(gateway.toOctets());
    if (length() == Ip6Address.BYTE_LENGTH +
            RouteAttribute.ROUTE_ATTRIBUTE_HEADER_LENGTH) {
        cb.writeBytes(buffer, Ip6Address.BYTE_LENGTH);
    } else if (length() == Ip4Address.BYTE_LENGTH +
            RouteAttribute.ROUTE_ATTRIBUTE_HEADER_LENGTH) {
        cb.writeBytes(buffer, Ip4Address.BYTE_LENGTH);
    } else {
        throw new IllegalArgumentException("Gateway address length incorrect!");
    }
}
 
Example #7
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    NeighborSolicitation ns = new NeighborSolicitation();
    ICMP6 icmp6 = new ICMP6();
    icmp6.setPayload(ns);
    IPv6 ipv6 = new IPv6();
    ipv6.setPayload(icmp6);
    ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1").toOctets());
    ipv6.setSourceAddress(Ip6Address.valueOf("::").toOctets());
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC2.toBytes())
            .setDestinationMACAddress(BCMAC2)
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #8
Source File: RouteAttributeGateway.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a decoder for a gateway route attribute.
 *
 * @return gateway route attribute decoder
 */
public static RouteAttributeDecoder<RouteAttributeGateway> decoder() {
    return (int length, int type, byte[] value) -> {

        IpAddress gateway;
        if (value.length == Ip4Address.BYTE_LENGTH) {
            gateway = IpAddress.valueOf(IpAddress.Version.INET, value);
        } else if (value.length == Ip6Address.BYTE_LENGTH) {
            gateway = IpAddress.valueOf(IpAddress.Version.INET6, value);
        } else {
            throw new DeserializationException("Invalid address length");
        }

        return new RouteAttributeGateway(length, type, gateway);
    };
}
 
Example #9
Source File: DeviceConfiguration.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the router ipv6 address of segment router that has the
 * specified ip address in its subnets.
 *
 * @param destIpAddress target ip address
 * @return router ip address
 */
public Ip6Address getRouterIpAddressForASubnetHost(Ip6Address destIpAddress) {
    Interface matchIntf = srManager.interfaceService.getMatchingInterface(destIpAddress);

    if (matchIntf == null) {
        log.debug("No router was found for {}", destIpAddress);
        return null;
    }

    DeviceId routerDeviceId = matchIntf.connectPoint().deviceId();
    SegmentRouterInfo srInfo = deviceConfigMap.get(routerDeviceId);
    if (srInfo == null) {
        log.debug("No device config was found for {}", routerDeviceId);
        return null;
    }

    return srInfo.ipv6Loopback;
}
 
Example #10
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 #11
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    RouterSolicitation ns = new RouterSolicitation();
    ICMP6 icmp6 = new ICMP6();
    icmp6.setPayload(ns);
    IPv6 ipv6 = new IPv6();
    ipv6.setPayload(icmp6);
    ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::2").toOctets());
    ipv6.setSourceAddress(IP2);
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC2.toBytes())
            .setDestinationMACAddress(MacAddress.valueOf("33:33:00:00:00:02"))
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #12
Source File: IcmpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to handle the ndp replies.
 *
 * @param pkt the ndp packet reply and context information
 * @param hostService the host service
 */
private void handleNdpReply(NeighbourMessageContext pkt, HostService hostService) {
    if (isNdpForGateway(pkt)) {
        log.debug("Forwarding all the ip packets we stored");
        Ip6Address hostIpAddress = pkt.sender().getIp6Address();
        srManager.ipHandler.forwardPackets(pkt.inPort().deviceId(), hostIpAddress);
    } else {
        // NOTE: Ignore NDP packets except those target for the router
        //       We will reconsider enabling this when we have host learning support
        /*
        HostId hostId = HostId.hostId(pkt.dstMac(), pkt.vlan());
        Host targetHost = hostService.getHost(hostId);
        if (targetHost != null) {
            log.debug("Forwarding the reply to the host");
            pkt.forward(targetHost.location());
        } else {
            // We don't have to flood towards spine facing ports.
            if (pkt.vlan().equals(SegmentRoutingManager.INTERNAL_VLAN)) {
                return;
            }
            log.debug("Flooding the reply to the subnet");
            flood(pkt);
        }
        */
    }
}
 
Example #13
Source File: RouteAttributeDst.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a decoder for a destination address route attribute.
 *
 * @return destination address route attribute decoder
 */
public static RouteAttributeDecoder<RouteAttributeDst> decoder() {
    return (int length, int type, byte[] value) -> {

        IpAddress dstAddress;
        if (value.length == Ip4Address.BYTE_LENGTH) {
            dstAddress = IpAddress.valueOf(IpAddress.Version.INET, value);
        } else if (value.length == Ip6Address.BYTE_LENGTH) {
            dstAddress = IpAddress.valueOf(IpAddress.Version.INET6, value);
        } else {
            throw new DeserializationException("Invalid address length");
        }

        return new RouteAttributeDst(length, type, dstAddress);
    };
}
 
Example #14
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    IPv6 ipv6 = new IPv6();
    ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1").toOctets());
    ipv6.setSourceAddress(IP2);
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC2.toBytes())
            .setDestinationMACAddress(MacAddress.valueOf("33:33:00:00:00:01"))
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #15
Source File: DeviceConfiguration.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the device identifier or data plane identifier (dpid)
 * of a segment router given its router ipv6 address.
 *
 * @param ipAddress router ipv6 address
 * @return deviceId device identifier
 */
public DeviceId getDeviceId(Ip6Address ipAddress) {
    for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
            deviceConfigMap.entrySet()) {
        if (entry.getValue().ipv6Loopback.equals(ipAddress)) {
            return entry.getValue().deviceId;
        }
    }

    return null;
}
 
Example #16
Source File: DeviceConfiguration.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Ip6Address getRouterIpv6(DeviceId deviceId) throws DeviceConfigNotFoundException {
    SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
    if (srinfo != null) {
        log.trace("getRouterIpv6 for device{} is {}", deviceId, srinfo.ipv6Loopback);
        return srinfo.ipv6Loopback;
    } else {
        String message = "getRouterIpv6 fails for device: " + deviceId + ".";
        throw new DeviceConfigNotFoundException(message);
    }
}
 
Example #17
Source File: Dhcp6IaPrefixOption.java    From onos with Apache License 2.0 5 votes vote down vote up
public static Deserializer<Dhcp6Option> deserializer() {
    return (data, offset, length) -> {
        Dhcp6IaPrefixOption iaPrefixOption = new Dhcp6IaPrefixOption();
        Dhcp6Option dhcp6Option =
                Dhcp6Option.deserializer().deserialize(data, offset, length);
        iaPrefixOption.setPayload(dhcp6Option.getPayload());
        if (dhcp6Option.getLength() < DEFAULT_LEN) {
            throw new DeserializationException("Invalid length of IA prefix option");
        }
        ByteBuffer bb = ByteBuffer.wrap(dhcp6Option.getData());
        iaPrefixOption.preferredLifetime = bb.getInt();
        iaPrefixOption.validLifetime = bb.getInt();
        iaPrefixOption.prefixLength = bb.get();
        byte[] ipv6Pref = new byte[Ip6Address.BYTE_LENGTH];
        bb.get(ipv6Pref);
        iaPrefixOption.ip6Prefix = Ip6Address.valueOf(ipv6Pref);

        // options length of IA Address option
        int optionsLen = dhcp6Option.getLength() - DEFAULT_LEN;
        if (optionsLen > 0) {
            byte[] optionsData = new byte[optionsLen];
            bb.get(optionsData);
            iaPrefixOption.options =
                    Data.deserializer().deserialize(optionsData, 0, optionsLen);
        }
        return iaPrefixOption;
    };
}
 
Example #18
Source File: Dhcp6IndirectPacketClassifier.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean match(PacketContext packet) {

    Ethernet eth = packet.inPacket().parsed();

    if (eth.getEtherType() == Ethernet.TYPE_IPV6) {
        IPv6 ipv6Packet = (IPv6) eth.getPayload();

        if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_UDP) {
            UDP udpPacket = (UDP) ipv6Packet.getPayload();
            //Indirectly connected host
            if (udpPacket.getDestinationPort() == UDP.DHCP_V6_SERVER_PORT &&
                    udpPacket.getSourcePort() == UDP.DHCP_V6_SERVER_PORT &&
                    Arrays.equals(ipv6Packet.getDestinationAddress(),
                            Ip6Address.valueOf("ff02::1:2").toOctets())) {
                DHCP6 relayMessage = (DHCP6) udpPacket.getPayload();
                DHCP6 dhcp6 = (DHCP6) relayMessage.getOptions().stream()
                        .filter(opt -> opt instanceof Dhcp6RelayOption)
                        .map(BasePacket::getPayload)
                        .map(pld -> (DHCP6) pld)
                        .findFirst()
                        .orElse(null);

                if (dhcp6.getMsgType() == DHCP6.MsgType.SOLICIT.value()) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example #19
Source File: DefaultNeighbourMessageContext.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts context information from NDP packets.
 *
 * @param eth input Ethernet frame that is thought to be NDP
 * @param inPort in port
 * @param actions actions to take
 * @return MessageContext object if the packet was a valid NDP packet,
 * otherwise null
 */
private static NeighbourMessageContext createNdpContext(Ethernet eth,
                                                        ConnectPoint inPort,
                                                        NeighbourMessageActions actions) {
    if (eth.getEtherType() != Ethernet.TYPE_IPV6) {
        return null;
    }
    IPv6 ipv6 = (IPv6) eth.getPayload();

    if (ipv6.getNextHeader() != IPv6.PROTOCOL_ICMP6) {
        return null;
    }
    ICMP6 icmpv6 = (ICMP6) ipv6.getPayload();

    IpAddress sender = Ip6Address.valueOf(ipv6.getSourceAddress());
    IpAddress target;

    NeighbourMessageType type;
    if (icmpv6.getIcmpType() == ICMP6.NEIGHBOR_SOLICITATION) {
        type = NeighbourMessageType.REQUEST;
        NeighborSolicitation nsol = (NeighborSolicitation) icmpv6.getPayload();
        target = Ip6Address.valueOf(nsol.getTargetAddress());
    } else if (icmpv6.getIcmpType() == ICMP6.NEIGHBOR_ADVERTISEMENT) {
        type = NeighbourMessageType.REPLY;
        /*
         * sender and target are the same in the reply.
         * We use as target the destination ip.
         */
        target = Ip6Address.valueOf(ipv6.getDestinationAddress());
    } else {
        return null;
    }

    return new DefaultNeighbourMessageContext(actions, eth, inPort,
            NeighbourProtocol.NDP, type, target, sender);
}
 
Example #20
Source File: IPv6AddressTlv.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Reads the channel buffer and returns object of IPv6AddressTlv.
 *
 * @param cb channelBuffer
 * @param type address type
 * @return object of IPv6AddressTlv
 * @throws BgpParseException while parsing IPv6AddressTlv
 */
public static IPv6AddressTlv read(ChannelBuffer cb, short type) throws BgpParseException {
    InetAddress ipAddress = Validation.toInetAddress(LENGTH, cb);
    if (ipAddress.isMulticastAddress()) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
    }
    Ip6Address address = Ip6Address.valueOf(ipAddress);
    return IPv6AddressTlv.of(address, type);
}
 
Example #21
Source File: Ip6AddressSerializer.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, Ip6Address object) {
    byte[] octs = object.toOctets();
    // It is always Ip6Address.BYTE_LENGTH
    output.writeInt(octs.length);
    output.writeBytes(octs);
}
 
Example #22
Source File: ReactiveRoutingConfiguration.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isIpAddressLocal(IpAddress ipAddress) {
    if (ipAddress.isIp4()) {
        return localPrefixTable4.getValuesForKeysPrefixing(
                createBinaryString(
                IpPrefix.valueOf(ipAddress, Ip4Address.BIT_LENGTH)))
                .iterator().hasNext();
    } else {
        return localPrefixTable6.getValuesForKeysPrefixing(
                createBinaryString(
                IpPrefix.valueOf(ipAddress, Ip6Address.BIT_LENGTH)))
                .iterator().hasNext();
    }
}
 
Example #23
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 5 votes vote down vote up
private ForwardingObjective.Builder dad6FwdObjective(PortNumber port, int priority) {
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
    sBuilder.matchEthType(TYPE_IPV6)
            .matchIPv6Src(Ip6Address.ZERO.toIpPrefix());
            // TODO CORD-1672 Fix this when OFDPA can distinguish ::/0 and ::/128 correctly
            // .matchIPProtocol(PROTOCOL_ICMP6)
            // .matchIcmpv6Type(NEIGHBOR_SOLICITATION);
    if (port != null) {
        sBuilder.matchInPort(port);
    }

    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    tBuilder.wipeDeferred();
    return fwdObjBuilder(sBuilder.build(), tBuilder.build(), priority);
}
 
Example #24
Source File: IcmpHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns link-local IP of given connect point.
 *
 * @param cp connect point
 * @return optional link-local IP
 */
private Optional<Ip6Address> getLinkLocalIp(ConnectPoint cp) {
    return srManager.interfaceService.getInterfacesByPort(cp)
            .stream()
            .map(Interface::mac)
            .map(MacAddress::toBytes)
            .map(IPv6::getLinkLocalAddress)
            .map(Ip6Address::valueOf)
            .findFirst();
}
 
Example #25
Source File: BgpPrefixAttrOspfFwdAddr.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Reads the OSPF Forwarding Address.
 *
 * @param cb ChannelBuffer
 * @return object of BgpPrefixAttrOSPFFwdAddr
 * @throws BgpParseException while parsing BgpPrefixAttrOspfFwdAddr
 */
public static BgpPrefixAttrOspfFwdAddr read(ChannelBuffer cb)
        throws BgpParseException {
    short lsAttrLength;
    byte[] ipBytes;
    Ip4Address ip4RouterId = null;
    Ip6Address ip6RouterId = null;

    lsAttrLength = cb.readShort();
    ipBytes = new byte[lsAttrLength];

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

    cb.readBytes(ipBytes);

    if (IPV4_LEN == lsAttrLength) {
        ip4RouterId = Ip4Address.valueOf(ipBytes);
    } else if (IPV6_LEN == lsAttrLength) {
        ip6RouterId = Ip6Address.valueOf(ipBytes);
    }

    return BgpPrefixAttrOspfFwdAddr.of(lsAttrLength, ip4RouterId,
                                       ip6RouterId);
}
 
Example #26
Source File: OspfDeviceTedImplTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests ipv6RouterIds() setter method.
 */
@Test
public void testSetIpv6RouterIds() throws Exception {
    List list = new ArrayList();
    list.add(Ip6Address.valueOf(1));
    ospfDeviceTed.setIpv6RouterIds(list);
    assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1));
}
 
Example #27
Source File: OspfDeviceTedImplTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests ipv6RouterIds() getter method.
 */
@Test
public void testIpv6RouterIds() throws Exception {
    List list = new ArrayList();
    list.add(Ip6Address.valueOf(1));
    ospfDeviceTed.setIpv6RouterIds(list);
    assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1));
}
 
Example #28
Source File: SimpleFabricManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public FabricSubnet fabricSubnet(IpAddress ip) {
    if (ip.isIp4()) {
        return ip4SubnetTable.getValueForLongestKeyPrefixing(
                 createBinaryString(IpPrefix.valueOf(ip, Ip4Address.BIT_LENGTH)));
    } else {
        return ip6SubnetTable.getValueForLongestKeyPrefixing(
                 createBinaryString(IpPrefix.valueOf(ip, Ip6Address.BIT_LENGTH)));
    }
}
 
Example #29
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 #30
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)));
}