org.onosproject.net.host.InterfaceIpAddress Java Examples

The following examples show how to use org.onosproject.net.host.InterfaceIpAddress. 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: IcmpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processPacketIn(InboundPacket pkt) {

        boolean ipMatches = false;
        Ethernet ethernet = pkt.parsed();
        IPv4 ipv4 = (IPv4) ethernet.getPayload();
        ConnectPoint connectPoint = pkt.receivedFrom();
        IpAddress destIpAddress = IpAddress.valueOf(ipv4.getDestinationAddress());
        Interface targetInterface = interfaceService.getMatchingInterface(destIpAddress);

        if (targetInterface == null) {
            log.trace("No matching interface for {}", destIpAddress);
            return;
        }

        for (InterfaceIpAddress interfaceIpAddress: targetInterface.ipAddressesList()) {
            if (interfaceIpAddress.ipAddress().equals(destIpAddress)) {
                ipMatches = true;
                break;
            }
        }

        if (((ICMP) ipv4.getPayload()).getIcmpType() == ICMP.TYPE_ECHO_REQUEST &&
                ipMatches) {
            sendIcmpResponse(ethernet, connectPoint);
        }
    }
 
Example #2
Source File: DeviceConfiguration.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the subnet configuration of given device and port.
 *
 * @param deviceId Device ID
 * @param port Port number
 * @return The subnets configured on given port or empty set if
 *         the port is unconfigured or suppressed.
 */
public Set<IpPrefix> getPortSubnets(DeviceId deviceId, PortNumber port) {
    ConnectPoint connectPoint = new ConnectPoint(deviceId, port);

    if (isSuppressedPort(connectPoint)) {
        return Collections.emptySet();
    }

    Set<IpPrefix> subnets = srManager.interfaceService.getInterfacesByPort(connectPoint).stream()
            .flatMap(intf -> intf.ipAddressesList().stream())
            .map(InterfaceIpAddress::subnetAddress)
            .collect(Collectors.toSet());

    if (subnets.isEmpty()) {
        log.debug(NO_SUBNET, connectPoint);
        return Collections.emptySet();
    }
    return subnets;
}
 
Example #3
Source File: ControlPlaneRedirectManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Setup Interface expectation for all Testcases.
 **/
private void setUpInterfaceService() {
    List<InterfaceIpAddress> interfaceIpAddresses1 = new ArrayList<>();
    interfaceIpAddresses1
            .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"), IpPrefix.valueOf("192.168.10.0/24")));
    Interface sw1Eth1 = new Interface(SW1_ETH1.deviceId().toString(), SW1_ETH1, interfaceIpAddresses1,
            MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE);
    interfaces.add(sw1Eth1);

    List<InterfaceIpAddress> interfaceIpAddresses2 = new ArrayList<>();
    interfaceIpAddresses2
            .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), IpPrefix.valueOf("192.168.20.0/24")));
    Interface sw1Eth2 = new Interface(SW1_ETH1.deviceId().toString(), SW1_ETH2, interfaceIpAddresses2,
            MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE);
    interfaces.add(sw1Eth2);

    List<InterfaceIpAddress> interfaceIpAddresses3 = new ArrayList<>();
    interfaceIpAddresses3
            .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), IpPrefix.valueOf("192.168.30.0/24")));
    Interface sw1Eth3 = new Interface(SW1_ETH1.deviceId().toString(), SW1_ETH3, interfaceIpAddresses3,
            MacAddress.valueOf("00:00:00:00:00:03"), VlanId.NONE);
    interfaces.add(sw1Eth3);

}
 
Example #4
Source File: ControlPlaneRedirectManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveInterface() {
    ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4));
    List<InterfaceIpAddress> interfaceIpAddresses = new ArrayList<>();
    interfaceIpAddresses.add(
            new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"))
    );
    interfaceIpAddresses.add(
            new InterfaceIpAddress(IpAddress.valueOf("2000::ff"), IpPrefix.valueOf("2000::ff/120"))
    );

    Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses,
            MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
    EasyMock.reset(flowObjectiveService);
    expect(flowObjectiveService.allocateNextId()).andReturn(1).anyTimes();

    setUpInterfaceConfiguration(sw1Eth4, false);
    replay(flowObjectiveService);
    interfaceListener.event(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_REMOVED, sw1Eth4, 500L));
    verify(flowObjectiveService);
}
 
Example #5
Source File: ControlPlaneRedirectManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests adding while updating the networkConfig.
 */
@Test
public void testAddInterface() {
    ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4));
    List<InterfaceIpAddress> interfaceIpAddresses = new ArrayList<>();
    interfaceIpAddresses.add(
            new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"))
    );
    interfaceIpAddresses.add(
            new InterfaceIpAddress(IpAddress.valueOf("2000::ff"), IpPrefix.valueOf("2000::ff/120"))
    );

    Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses,
            MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
    interfaces.add(sw1Eth4);

    EasyMock.reset(flowObjectiveService);
    expect(flowObjectiveService.allocateNextId()).andReturn(1).anyTimes();

    setUpInterfaceConfiguration(sw1Eth4, true);
    replay(flowObjectiveService);
    interfaceListener.event(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, sw1Eth4, 500L));
    verify(flowObjectiveService);
}
 
Example #6
Source File: ControlPlaneRedirectManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests adding while updating the networkConfig.
 */
@Test
public void testUpdateNetworkConfig() {
    ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4));
    List<InterfaceIpAddress> interfaceIpAddresses = new ArrayList<>();
    interfaceIpAddresses.add(
            new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"))
    );
    interfaceIpAddresses.add(
            new InterfaceIpAddress(IpAddress.valueOf("2000::ff"), IpPrefix.valueOf("2000::ff/120"))
    );

    Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses,
            MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
    interfaces.add(sw1Eth4);
    EasyMock.reset(flowObjectiveService);
    setUpFlowObjectiveService();
    networkConfigListener
            .event(new NetworkConfigEvent(Type.CONFIG_UPDATED, dev3, RoutingService.ROUTER_CONFIG_CLASS));
    networkConfigService.addListener(networkConfigListener);
    verify(flowObjectiveService);
}
 
Example #7
Source File: ControlPlaneRedirectManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests adding new Device to a openflow router.
 */
@Test
public void testAddDevice() {
    ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4));
    List<InterfaceIpAddress> interfaceIpAddresses = new ArrayList<>();
    interfaceIpAddresses.add(
            new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"))
    );
    interfaceIpAddresses.add(
            new InterfaceIpAddress(IpAddress.valueOf("2000::ff"), IpPrefix.valueOf("2000::ff/120"))
    );

    Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses,
            MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
    interfaces.add(sw1Eth4);
    EasyMock.reset(flowObjectiveService);
    setUpFlowObjectiveService();
    deviceListener.event(new DeviceEvent(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED, dev3));
    verify(flowObjectiveService);
}
 
Example #8
Source File: InterfaceAddCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected void doExecute() {
    InterfaceAdminService interfaceService = get(InterfaceAdminService.class);

    List<InterfaceIpAddress> ipAddresses = Lists.newArrayList();
    if (ips != null) {
        for (String strIp : ips) {
            ipAddresses.add(InterfaceIpAddress.valueOf(strIp));
        }
    }

    MacAddress macAddr = mac == null ? null : MacAddress.valueOf(mac);

    VlanId vlanId = vlan == null ? VlanId.NONE : VlanId.vlanId(Short.parseShort(vlan));

    Interface intf = new Interface(name,
            ConnectPoint.deviceConnectPoint(connectPoint),
            ipAddresses, macAddr, vlanId);

    interfaceService.add(intf);

    print("Interface added");
}
 
Example #9
Source File: RouterAdvertisementDeviceConfigTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    InputStream jsonStream = RouterAdvertisementDeviceConfigTest.class
            .getResourceAsStream("/device.json");

    prefixes = new ArrayList<InterfaceIpAddress>();

    prefixes.add(InterfaceIpAddress.valueOf("2001:0558:FF10:04C9::6:100/120"));
    prefixes.add(InterfaceIpAddress.valueOf("2001:0558:FF10:04C9::7:100/120"));

    DeviceId subject = DeviceId.deviceId("of:0000000000000001");
    String key = "routeradvertisement";
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(jsonStream);
    ConfigApplyDelegate delegate = new MockDelegate();

    config = new RouterAdvertisementDeviceConfig();
    config.init(subject, key, jsonNode, mapper, delegate);

}
 
Example #10
Source File: RouterAdvertisementManager.java    From onos with Apache License 2.0 5 votes vote down vote up
RAWorkerThread(ConnectPoint connectPoint, List<InterfaceIpAddress> ipAddresses, int period,
               MacAddress macAddress, byte[] ipv6Address) {
    this.connectPoint = connectPoint;
    this.ipAddresses = ipAddresses;
    retransmitPeriod = period;
    solicitHostMac = macAddress;
    solicitHostAddress = ipv6Address;
}
 
Example #11
Source File: VplsTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Interface getMatchingInterface(IpAddress ip) {
    return AVAILABLE_INTERFACES.stream()
            .filter(intf -> intf.ipAddressesList().stream()
                    .map(InterfaceIpAddress::ipAddress)
                    .filter(ip::equals)
                    .findAny()
                    .isPresent())
            .findFirst()
            .orElse(null);
}
 
Example #12
Source File: VplsTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Interface> getInterfacesByIp(IpAddress ip) {
    return AVAILABLE_INTERFACES.stream()
            .filter(intf -> intf.ipAddressesList().stream()
                        .map(InterfaceIpAddress::ipAddress)
                        .filter(ip::equals)
                        .findAny()
                        .isPresent())
            .collect(Collectors.toSet());
}
 
Example #13
Source File: DefaultFabricNetworkTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private static Interface createInterface(int index) {

        String name = "INTF_NAME_" + index;
        ConnectPoint cp = ConnectPoint.fromString("of:0011223344556677/" + index);
        InterfaceIpAddress intfIp1 = InterfaceIpAddress.valueOf("10.10.10." + index + "/32");
        InterfaceIpAddress intfIp2 = InterfaceIpAddress.valueOf("20.20.20." + index + "/32");
        List<InterfaceIpAddress> intfIps = ImmutableList.of(intfIp1, intfIp2);
        MacAddress mac = MacAddress.valueOf("00:00:00:00:00:00");
        VlanId vlanId = VlanId.NONE;

        return new Interface(name, cp, intfIps, mac, vlanId);
    }
 
Example #14
Source File: NdpReplyComponent.java    From ngsdn-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Returns all IPv6 addresses associated with the given interface.
 *
 * @param iface interface instance
 * @return collection of IPv6 addresses
 */
private Collection<Ip6Address> getIp6Addresses(Interface iface) {
    return iface.ipAddressesList()
            .stream()
            .map(InterfaceIpAddress::ipAddress)
            .filter(IpAddress::isIp6)
            .map(IpAddress::getIp6Address)
            .collect(Collectors.toSet());
}
 
Example #15
Source File: VplsTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Interface> getMatchingInterfaces(IpAddress ip) {
    return AVAILABLE_INTERFACES.stream()
            .filter(intf -> intf.ipAddressesList().stream()
                    .map(InterfaceIpAddress::ipAddress)
                    .filter(ip::equals)
                    .findAny()
                    .isPresent())
            .collect(Collectors.toSet());
}
 
Example #16
Source File: DeviceConfiguration.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns configured subnets for a segment router.
 *
 * @param deviceId device identifier
 * @return list of ip prefixes or null if not found
 */
public Set<IpPrefix> getConfiguredSubnets(DeviceId deviceId) {
    Set<IpPrefix> subnets = srManager.interfaceService.getInterfaces().stream()
            .filter(intf -> Objects.equals(deviceId, intf.connectPoint().deviceId()))
            .flatMap(intf -> intf.ipAddressesList().stream())
            .map(InterfaceIpAddress::subnetAddress)
            .collect(Collectors.toSet());

    if (subnets.isEmpty()) {
        log.debug(NO_SUBNET, deviceId);
        return Collections.emptySet();
    }
    return subnets;
}
 
Example #17
Source File: RouterAdvertisementManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

    // TODO : Validate Router Solicitation

    // Pause already running unsolicited RA threads in received connect point
    ConnectPoint connectPoint = packet.receivedFrom();
    List<InterfaceIpAddress> addresses = deactivateRouterAdvertisement(connectPoint);

    /* Multicast RA(ie. Unsolicited RA) TX time is not preciously tracked so to make sure that
     * Unicast RA(ie. Router Solicitation Response) is TXed before Mulicast RA
     * logic adapted here is disable Mulicast RA, TX Unicast RA and then restore Multicast RA.
     */
    log.trace("Processing Router Solicitations from {}", connectPoint);
    try {
        Ethernet ethernet = packet.parsed();
        IPv6 ipv6 = (IPv6) ethernet.getPayload();
        RAWorkerThread worker = new RAWorkerThread(connectPoint,
                addresses, raThreadDelay, ethernet.getSourceMAC(), ipv6.getSourceAddress());
        // TODO : Estimate TX time as in RFC 4861, Section 6.2.6 and schedule TX based on it
        CompletableFuture<Void> sraHandlerFuture = CompletableFuture.runAsync(worker, executors);
        sraHandlerFuture.get();
    } catch (Exception e) {
        log.error("Failed to respond to router solicitation. {}", e);
    } finally {
        activateRouterAdvertisement(connectPoint, addresses);
        log.trace("Restored Unsolicited Router Advertisements on {}", connectPoint);
    }
}
 
Example #18
Source File: PeerConnectivityManager.java    From onos with Apache License 2.0 5 votes vote down vote up
private Collection<PointToPointIntent> buildSpeakerIntents(BgpConfig.BgpSpeakerConfig speaker,
                                                           EncapsulationType encap) {
    List<PointToPointIntent> intents = new ArrayList<>();

    // Get the BGP Speaker VLAN Id
    VlanId bgpSpeakerVlanId = speaker.vlan();

    for (IpAddress peerAddress : speaker.peers()) {
        Interface peeringInterface = interfaceService.getMatchingInterface(peerAddress);

        if (peeringInterface == null) {
            log.debug("No peering interface found for peer {} on speaker {}",
                    peerAddress, speaker);
            continue;
        }

        IpAddress bgpSpeakerAddress = null;
        for (InterfaceIpAddress address : peeringInterface.ipAddressesList()) {
            if (address.subnetAddress().contains(peerAddress)) {
                bgpSpeakerAddress = address.ipAddress();
                break;
            }
        }

        checkNotNull(bgpSpeakerAddress);

        VlanId peerVlanId = peeringInterface.vlan();

        intents.addAll(buildIntents(speaker.connectPoint(), bgpSpeakerVlanId,
                                    bgpSpeakerAddress,
                                    peeringInterface.connectPoint(),
                                    peerVlanId,
                                    peerAddress,
                                    encap));
    }

    return intents;
}
 
Example #19
Source File: SdnIpFibTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up the interface service.
 */
private void setUpInterfaceService() {
    List<InterfaceIpAddress> iIps1 = Lists.newArrayList();
    iIps1.add(IIP1);
    Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, iIps1, MAC1, VLAN10);
    interfaces.add(sw1Eth1);

    List<InterfaceIpAddress> iIps2 = Lists.newArrayList();
    iIps2.add(IIP2);
    Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, iIps2, MAC2, VLAN20);
    interfaces.add(sw2Eth1);

    List<InterfaceIpAddress> iIps3 = Lists.newArrayList();
    iIps3.add(IIP3);
    Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, iIps3, MAC3, NO_VLAN);
    interfaces.add(sw3Eth1);

    expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn(
            Collections.singleton(sw1Eth1)).anyTimes();
    expect(interfaceService.getMatchingInterface(IP1))
            .andReturn(sw1Eth1).anyTimes();
    expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn(
            Collections.singleton(sw2Eth1)).anyTimes();
    expect(interfaceService.getMatchingInterface(IP2))
            .andReturn(sw2Eth1).anyTimes();
    expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn(
            Collections.singleton(sw3Eth1)).anyTimes();
    expect(interfaceService.getMatchingInterface(IP3))
            .andReturn(sw3Eth1).anyTimes();
    expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
}
 
Example #20
Source File: PimInterface.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Return a single "best" IP address.
 *
 * @return the chosen IP address or null if none
 */
public IpAddress getIpAddress() {
    if (onosInterface.ipAddressesList().isEmpty()) {
        return null;
    }

    IpAddress ipaddr = null;
    for (InterfaceIpAddress ifipaddr : onosInterface.ipAddressesList()) {
        ipaddr = ifipaddr.ipAddress();
        break;
    }
    return ipaddr;
}
 
Example #21
Source File: InterfaceConfig.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves all interfaces configured on this port.
 *
 * @return set of interfaces
 * @throws ConfigException if there is any error in the JSON config
 */
public Set<Interface> getInterfaces() throws ConfigException {
    Set<Interface> interfaces = Sets.newHashSet();

    try {
        for (JsonNode intfNode : array) {
            String name = intfNode.path(NAME).asText(null);

            List<InterfaceIpAddress> ips = getIps(intfNode);

            String mac = intfNode.path(MAC).asText();
            MacAddress macAddr = mac.isEmpty() ? null : MacAddress.valueOf(mac);

            VlanId vlan = getVlan(intfNode, VLAN);
            VlanId vlanUntagged = getVlan(intfNode, VLAN_UNTAGGED);
            Set<VlanId> vlanTagged = getVlans(intfNode, VLAN_TAGGED);
            VlanId vlanNative = getVlan(intfNode, VLAN_NATIVE);

            interfaces.add(new Interface(name, subject, ips, macAddr, vlan,
                    vlanUntagged, vlanTagged, vlanNative));
        }
    } catch (IllegalArgumentException e) {
        throw new ConfigException(CONFIG_VALUE_ERROR, e);
    }

    return interfaces;
}
 
Example #22
Source File: InterfaceConfig.java    From onos with Apache License 2.0 5 votes vote down vote up
private List<InterfaceIpAddress> getIps(JsonNode node) {
    List<InterfaceIpAddress> ips = Lists.newArrayList();

    JsonNode ipsNode = node.get(IPS);
    if (ipsNode != null) {
        ipsNode.forEach(jsonNode ->
                ips.add(InterfaceIpAddress.valueOf(jsonNode.asText())));
    }

    return ips;
}
 
Example #23
Source File: InterfaceConfigTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private void checkInterface(Interface fetchedInterface, int index) {
    String name = getName(index);
    assertThat(fetchedInterface, notNullValue());
    assertThat(fetchedInterface.name(), is(name));
    assertThat(fetchedInterface.connectPoint(), is(cp1));
    assertThat(fetchedInterface.mac(), is(getMac(index)));
    List<InterfaceIpAddress> fetchedIpAddresses = fetchedInterface.ipAddressesList();
    assertThat(fetchedIpAddresses, hasItems(getIp(index, 1), getIp(index, 2)));
}
 
Example #24
Source File: InterfaceManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private Interface createInterface(int i) {
    ConnectPoint cp = createConnectPoint(i);

    InterfaceIpAddress ia = InterfaceIpAddress.valueOf("192.168." + i + ".1/24");

    Interface intf = new Interface(Interface.NO_INTERFACE_NAME, cp,
            Collections.singletonList(ia),
            MacAddress.valueOf(i),
            VlanId.vlanId((short) i));

    return intf;
}
 
Example #25
Source File: InterfaceCodec.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Interface decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }

    String name = nullIsIllegal(json.findValue(NAME),
            NAME + MISSING_NAME_MESSAGE).asText();
    ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(nullIsIllegal(json.findValue(CONNECT_POINT),
            CONNECT_POINT + MISSING_CONNECT_POINT_MESSAGE).asText());
    List<InterfaceIpAddress> ipAddresses = Lists.newArrayList();
    if (json.findValue(IPS) != null) {
        json.findValue(IPS).forEach(ip -> {
            ipAddresses.add(InterfaceIpAddress.valueOf(ip.asText()));
        });
    }

    MacAddress macAddr =  json.findValue(MAC) == null ?
            null : MacAddress.valueOf(json.findValue(MAC).asText());
    VlanId vlanId =  json.findValue(VLAN) == null ?
            VlanId.NONE : VlanId.vlanId(Short.parseShort(json.findValue(VLAN).asText()));
    Interface inter = new Interface(
            name,
            connectPoint,
            ipAddresses,
            macAddr,
            vlanId);

    return inter;
}
 
Example #26
Source File: ControlPlaneRedirectManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Interface getMatchingInterface(IpAddress ip) {
    Interface intff = null;
    for (Interface intf : interfaces) {
        for (InterfaceIpAddress address : intf.ipAddressesList()) {
            if (address.ipAddress().equals(ip)) {
                intff = intf;
                break;
            }
        }
    }

    return intff;
}
 
Example #27
Source File: NdpReplyComponent.java    From ngsdn-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Returns all IPv6 addresses associated with the given interface.
 *
 * @param iface interface instance
 * @return collection of IPv6 addresses
 */
private Collection<Ip6Address> getIp6Addresses(Interface iface) {
    return iface.ipAddressesList()
            .stream()
            .map(InterfaceIpAddress::ipAddress)
            .filter(IpAddress::isIp6)
            .map(IpAddress::getIp6Address)
            .collect(Collectors.toSet());
}
 
Example #28
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 #29
Source File: NdpReplyComponent.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
private Collection<Ip6Address> getIp6Addresses(Interface iface) {
    return iface.ipAddressesList()
            .stream()
            .map(InterfaceIpAddress::ipAddress)
            .filter(IpAddress::isIp6)
            .map(IpAddress::getIp6Address)
            .collect(Collectors.toSet());
}
 
Example #30
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());
}