Search in sources :

Example 6 with InterfaceIpAddress

use of org.onosproject.net.host.InterfaceIpAddress in project onos by opennetworkinglab.

the class ControlPlaneRedirectManagerTest method testAddInterface.

/**
 * 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);
}
Also used : InterfaceEvent(org.onosproject.net.intf.InterfaceEvent) ArrayList(java.util.ArrayList) ConnectPoint(org.onosproject.net.ConnectPoint) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Interface(org.onosproject.net.intf.Interface) Test(org.junit.Test)

Example 7 with InterfaceIpAddress

use of org.onosproject.net.host.InterfaceIpAddress in project onos by opennetworkinglab.

the class RouterAdvertisementDeviceConfigTest method setUp.

@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);
}
Also used : InputStream(java.io.InputStream) DeviceId(org.onosproject.net.DeviceId) JsonNode(com.fasterxml.jackson.databind.JsonNode) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Before(org.junit.Before)

Example 8 with InterfaceIpAddress

use of org.onosproject.net.host.InterfaceIpAddress in project onos by opennetworkinglab.

the class InterfaceManagerTest method testUpdateInterface.

@Test
public void testUpdateInterface() throws Exception {
    ConnectPoint cp = createConnectPoint(1);
    // Create an interface that is the same as the existing one, but adds a
    // new IP address
    Interface intf = createInterface(1);
    List<InterfaceIpAddress> addresses = Lists.newArrayList(intf.ipAddressesList());
    addresses.add(InterfaceIpAddress.valueOf("192.168.100.1/24"));
    intf = new Interface(Interface.NO_INTERFACE_NAME, intf.connectPoint(), addresses, intf.mac(), intf.vlan());
    // Create a new interface on the same connect point as the existing one
    InterfaceIpAddress newAddr = InterfaceIpAddress.valueOf("192.168.101.1/24");
    Interface newIntf = new Interface(Interface.NO_INTERFACE_NAME, cp, Collections.singletonList(newAddr), MacAddress.valueOf(101), VlanId.vlanId((short) 101));
    Set<Interface> interfaces = Sets.newHashSet(intf, newIntf);
    // New interface config updates the existing interface and adds a new
    // interface to the same connect point
    InterfaceConfig oldIc = new TestInterfaceConfig(cp, Sets.newHashSet(intf));
    InterfaceConfig ic = new TestInterfaceConfig(cp, interfaces);
    configs.put(cp, ic);
    NetworkConfigEvent event = new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_UPDATED, cp, ic, oldIc, CONFIG_CLASS);
    // Send in the event signalling the interfaces for this connect point
    // have been updated
    listener.event(event);
    assertEquals(NUM_INTERFACES + 1, interfaceManager.getInterfaces().size());
    assertEquals(interfaces, interfaceManager.getInterfacesByPort(cp));
}
Also used : InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) ConnectPoint(org.onosproject.net.ConnectPoint) Interface(org.onosproject.net.intf.Interface) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Test(org.junit.Test)

Example 9 with InterfaceIpAddress

use of org.onosproject.net.host.InterfaceIpAddress in project onos by opennetworkinglab.

the class Dhcp4HandlerImpl method processDhcpPacketFromClient.

/**
 * Build the DHCP discover/request packet with gateway IP(unicast packet).
 *
 * @param context the packet context
 * @param ethernetPacket the ethernet payload to process
 * @return processed packet
 */
private List<InternalPacket> processDhcpPacketFromClient(PacketContext context, Ethernet ethernetPacket, Set<Interface> clientInterfaces) {
    ConnectPoint receivedFrom = context.inPacket().receivedFrom();
    DeviceId receivedFromDevice = receivedFrom.deviceId();
    Ip4Address relayAgentIp = null;
    relayAgentIp = Dhcp4HandlerUtil.getRelayAgentIPv4Address(clientInterfaces);
    MacAddress relayAgentMac = clientInterfaces.iterator().next().mac();
    if (relayAgentIp == null || relayAgentMac == null) {
        log.warn("Missing DHCP relay agent interface Ipv4 addr config for " + "packet from client on port: {}. Aborting packet processing", clientInterfaces.iterator().next().connectPoint());
        return Lists.newArrayList();
    }
    log.debug("Multi DHCP V4 processDhcpPacketFromClient on port {}", clientInterfaces.iterator().next().connectPoint());
    // get dhcp header.
    Ethernet etherReply = (Ethernet) ethernetPacket.clone();
    IPv4 ipv4Packet = (IPv4) etherReply.getPayload();
    UDP udpPacket = (UDP) ipv4Packet.getPayload();
    DHCP dhcpPacket = (DHCP) udpPacket.getPayload();
    Ip4Address clientInterfaceIp = interfaceService.getInterfacesByPort(context.inPacket().receivedFrom()).stream().map(Interface::ipAddressesList).flatMap(Collection::stream).map(InterfaceIpAddress::ipAddress).filter(IpAddress::isIp4).map(IpAddress::getIp4Address).findFirst().orElse(null);
    if (clientInterfaceIp == null) {
        log.warn("Can't find interface IP for client interface for port {}", context.inPacket().receivedFrom());
        return Lists.newArrayList();
    }
    boolean isDirectlyConnected = directlyConnected(dhcpPacket);
    boolean directConnFlag = directlyConnected(dhcpPacket);
    // Multi DHCP Start
    ConnectPoint clientConnectionPoint = context.inPacket().receivedFrom();
    VlanId vlanIdInUse = VlanId.vlanId(ethernetPacket.getVlanID());
    Interface clientInterface = interfaceService.getInterfacesByPort(clientConnectionPoint).stream().filter(iface -> Dhcp4HandlerUtil.interfaceContainsVlan(iface, vlanIdInUse)).findFirst().orElse(null);
    List<InternalPacket> internalPackets = new ArrayList<>();
    List<DhcpServerInfo> serverInfoList = findValidServerInfo(directConnFlag);
    List<DhcpServerInfo> copyServerInfoList = new ArrayList<DhcpServerInfo>(serverInfoList);
    boolean serverFound = false;
    for (DhcpServerInfo serverInfo : copyServerInfoList) {
        etherReply = (Ethernet) ethernetPacket.clone();
        ipv4Packet = (IPv4) etherReply.getPayload();
        udpPacket = (UDP) ipv4Packet.getPayload();
        dhcpPacket = (DHCP) udpPacket.getPayload();
        if (!checkDhcpServerConnPt(directConnFlag, serverInfo)) {
            log.warn("Can't get server connect point, ignore");
            continue;
        }
        DhcpServerInfo newServerInfo = getHostInfoForServerInfo(serverInfo, serverInfoList);
        if (newServerInfo == null) {
            log.debug("Can't get server interface with host info resolved, ignore serverInfo {} serverInfoList {}", serverInfo, serverInfoList);
            continue;
        }
        Interface serverInterface = getServerInterface(newServerInfo);
        if (serverInterface == null) {
            log.debug("Can't get server interface, ignore for serverInfo {}, serverInfoList {}", serverInfo, serverInfoList);
            continue;
        }
        Ip4Address ipFacingServer = getFirstIpFromInterface(serverInterface);
        MacAddress macFacingServer = serverInterface.mac();
        log.debug("Interfacing server {} Mac : {} ", ipFacingServer, macFacingServer);
        if (ipFacingServer == null || macFacingServer == null) {
            log.debug("No IP address for server Interface {}", serverInterface);
            continue;
        }
        serverFound = true;
        log.debug("Server Info Found {}", serverInfo.getDhcpConnectMac());
        etherReply.setSourceMACAddress(macFacingServer);
        // set default info and replace with indirect if available later on.
        if (newServerInfo.getDhcpConnectMac().isPresent()) {
            etherReply.setDestinationMACAddress(newServerInfo.getDhcpConnectMac().get());
        }
        if (newServerInfo.getDhcpConnectVlan().isPresent()) {
            etherReply.setVlanID(newServerInfo.getDhcpConnectVlan().get().toShort());
        }
        ipv4Packet.setSourceAddress(ipFacingServer.toInt());
        ipv4Packet.setDestinationAddress(newServerInfo.getDhcpServerIp4().get().toInt());
        log.debug("Directly connected {}", isDirectlyConnected);
        log.debug("DHCP server IP: {}", newServerInfo.getDhcpServerIp4().get());
        if (isDirectlyConnected) {
            log.debug("Default DHCP server IP: {}", newServerInfo.getDhcpServerIp4().get());
            if (newServerInfo.getDhcpConnectMac().isPresent()) {
                etherReply.setDestinationMACAddress(newServerInfo.getDhcpConnectMac().get());
            }
            if (newServerInfo.getDhcpConnectVlan().isPresent()) {
                etherReply.setVlanID(newServerInfo.getDhcpConnectVlan().get().toShort());
            }
            ipv4Packet.setDestinationAddress(newServerInfo.getDhcpServerIp4().get().toInt());
            ConnectPoint inPort = context.inPacket().receivedFrom();
            VlanId vlanId = VlanId.vlanId(ethernetPacket.getVlanID());
            // add connected in port and vlan
            CircuitId cid = new CircuitId(inPort.toString(), vlanId);
            byte[] circuitId = cid.serialize();
            DhcpOption circuitIdSubOpt = new DhcpOption();
            circuitIdSubOpt.setCode(CIRCUIT_ID.getValue()).setLength((byte) circuitId.length).setData(circuitId);
            DhcpRelayAgentOption newRelayAgentOpt = new DhcpRelayAgentOption();
            newRelayAgentOpt.setCode(OptionCode_CircuitID.getValue());
            newRelayAgentOpt.addSubOption(circuitIdSubOpt);
            // Removes END option first
            List<DhcpOption> options = dhcpPacket.getOptions().stream().filter(opt -> opt.getCode() != OptionCode_END.getValue()).collect(Collectors.toList());
            // push relay agent option
            options.add(newRelayAgentOpt);
            // make sure option 255(End) is the last option
            DhcpOption endOption = new DhcpOption();
            endOption.setCode(OptionCode_END.getValue());
            options.add(endOption);
            dhcpPacket.setOptions(options);
            relayAgentIp = serverInfo.getRelayAgentIp4(receivedFromDevice).orElse(null);
            // Sets relay agent IP
            int effectiveRelayAgentIp = relayAgentIp != null ? relayAgentIp.toInt() : clientInterfaceIp.toInt();
            dhcpPacket.setGatewayIPAddress(effectiveRelayAgentIp);
            log.debug("In Default, Relay Agent IP {}", effectiveRelayAgentIp);
        } else {
            if (!newServerInfo.getDhcpServerIp4().isPresent()) {
            // do nothing
            } else if (!newServerInfo.getDhcpConnectMac().isPresent()) {
                continue;
            } else {
                relayAgentIp = newServerInfo.getRelayAgentIp4(receivedFromDevice).orElse(null);
                // Sets relay agent IP
                int effectiveRelayAgentIp = relayAgentIp != null ? relayAgentIp.toInt() : clientInterfaceIp.toInt();
                Ip4Address effectiveRealRealyAgentIP = relayAgentIp != null ? relayAgentIp : clientInterfaceIp;
                dhcpPacket.setGatewayIPAddress(effectiveRelayAgentIp);
                ipv4Packet.setSourceAddress(effectiveRealRealyAgentIP.toInt());
                log.debug("Source IP address set as relay agent IP with value: {}", effectiveRealRealyAgentIP);
            }
        }
        // Remove broadcast flag
        dhcpPacket.setFlags((short) 0);
        udpPacket.setPayload(dhcpPacket);
        // As a DHCP relay, the source port should be server port( instead
        // of client port.
        udpPacket.setSourcePort(UDP.DHCP_SERVER_PORT);
        udpPacket.setDestinationPort(UDP.DHCP_SERVER_PORT);
        ipv4Packet.setPayload(udpPacket);
        ipv4Packet.setTtl((byte) 64);
        etherReply.setPayload(ipv4Packet);
        InternalPacket internalPacket = InternalPacket.internalPacket(etherReply, serverInfo.getDhcpServerConnectPoint().get());
        internalPackets.add(internalPacket);
    }
    if (!serverFound) {
        log.warn("ProcessDhcp4PacketFromClient No Server Found");
    }
    return internalPackets;
}
Also used : DeviceService(org.onosproject.net.device.DeviceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) OptionCode_END(org.onlab.packet.DHCP.DHCPOptionCode.OptionCode_END) IgnoreDhcpConfig(org.onosproject.dhcprelay.config.IgnoreDhcpConfig) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) DhcpRelayStore(org.onosproject.dhcprelay.store.DhcpRelayStore) Ip4Address(org.onlab.packet.Ip4Address) Deactivate(org.osgi.service.component.annotations.Deactivate) OptionCode_MessageType(org.onlab.packet.DHCP.DHCPOptionCode.OptionCode_MessageType) Set(java.util.Set) MacAddress.valueOf(org.onlab.packet.MacAddress.valueOf) PacketService(org.onosproject.net.packet.PacketService) DhcpServerConfig(org.onosproject.dhcprelay.config.DhcpServerConfig) DeviceId(org.onosproject.net.DeviceId) LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT(org.onosproject.dhcprelay.OsgiPropertyConstants.LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT) Dictionary(java.util.Dictionary) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Pipeliner(org.onosproject.net.behaviour.Pipeliner) REMOVE(org.onosproject.net.flowobjective.Objective.Operation.REMOVE) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) RouteStore(org.onosproject.routeservice.RouteStore) ComponentContext(org.osgi.service.component.ComponentContext) LEARN_ROUTE_FROM_LEASE_QUERY(org.onosproject.dhcprelay.OsgiPropertyConstants.LEARN_ROUTE_FROM_LEASE_QUERY) HostListener(org.onosproject.net.host.HostListener) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) CIRCUIT_ID(org.onlab.packet.dhcp.DhcpRelayAgentOption.RelayAgentInfoOptions.CIRCUIT_ID) OptionCode_CircuitID(org.onlab.packet.DHCP.DHCPOptionCode.OptionCode_CircuitID) CircuitId(org.onlab.packet.dhcp.CircuitId) DhcpRelayAgentOption(org.onlab.packet.dhcp.DhcpRelayAgentOption) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TpPort(org.onlab.packet.TpPort) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) BasePacket(org.onlab.packet.BasePacket) Executor(java.util.concurrent.Executor) HostProvider(org.onosproject.net.host.HostProvider) VlanId(org.onlab.packet.VlanId) ProviderId(org.onosproject.net.provider.ProviderId) IPv4(org.onlab.packet.IPv4) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) DHCP(org.onlab.packet.DHCP) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Route(org.onosproject.routeservice.Route) HostLocation(org.onosproject.net.HostLocation) Interface(org.onosproject.net.intf.Interface) CoreService(org.onosproject.core.CoreService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) ByteBuffer(java.nio.ByteBuffer) Ethernet(org.onlab.packet.Ethernet) HostProviderService(org.onosproject.net.host.HostProviderService) HashMultimap(com.google.common.collect.HashMultimap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Collection(java.util.Collection) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) PacketContext(org.onosproject.net.packet.PacketContext) Optional(java.util.Optional) HostDescription(org.onosproject.net.host.HostDescription) ADD(org.onosproject.net.flowobjective.Objective.Operation.ADD) Multimap(com.google.common.collect.Multimap) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) OutboundPacket(org.onosproject.net.packet.OutboundPacket) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) UDP(org.onlab.packet.UDP) DhcpHandler(org.onosproject.dhcprelay.api.DhcpHandler) DhcpOption(org.onlab.packet.dhcp.DhcpOption) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Modified(org.osgi.service.component.annotations.Modified) PacketPriority(org.onosproject.net.packet.PacketPriority) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) DeviceId(org.onosproject.net.DeviceId) IPv4(org.onlab.packet.IPv4) Ip4Address(org.onlab.packet.Ip4Address) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) CircuitId(org.onlab.packet.dhcp.CircuitId) VlanId(org.onlab.packet.VlanId) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) UDP(org.onlab.packet.UDP) DhcpOption(org.onlab.packet.dhcp.DhcpOption) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) DHCP(org.onlab.packet.DHCP) ConnectPoint(org.onosproject.net.ConnectPoint) DhcpRelayAgentOption(org.onlab.packet.dhcp.DhcpRelayAgentOption) Ethernet(org.onlab.packet.Ethernet) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) IpAddress(org.onlab.packet.IpAddress) Interface(org.onosproject.net.intf.Interface) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress)

Example 10 with InterfaceIpAddress

use of org.onosproject.net.host.InterfaceIpAddress in project onos by opennetworkinglab.

the class PeerConnectivityManagerTest method setUpInterfaces.

/**
 * Sets up logical interfaces, which emulate the configured interfaces
 * in the SDN-IP application.
 *
 * @return configured interfaces as a map from interface name to Interface
 */
private Map<String, Interface> setUpInterfaces() {
    Map<String, Interface> configuredInterfaces = new HashMap<>();
    String interfaceSw1Eth1 = "s1-eth1";
    InterfaceIpAddress ia1 = new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"), IpPrefix.valueOf("192.168.10.0/24"));
    Interface intfsw1eth1 = new Interface(interfaceSw1Eth1, s1Eth1, Collections.singletonList(ia1), MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE);
    configuredInterfaces.put(interfaceSw1Eth1, intfsw1eth1);
    String interfaceSw2Eth1 = "s2-eth1";
    InterfaceIpAddress ia2 = new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), IpPrefix.valueOf("192.168.20.0/24"));
    Interface intfsw2eth1 = new Interface(interfaceSw2Eth1, s2Eth1, Collections.singletonList(ia2), MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE);
    configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1);
    String interfaceSw2Eth1intf2 = "s2-eth1_2";
    InterfaceIpAddress ia3 = new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), IpPrefix.valueOf("192.168.30.0/24"));
    Interface intfsw2eth1intf2 = new Interface(interfaceSw2Eth1intf2, s2Eth1, Collections.singletonList(ia3), MacAddress.valueOf("00:00:00:00:00:03"), VlanId.NONE);
    configuredInterfaces.put(interfaceSw2Eth1intf2, intfsw2eth1intf2);
    String interfaceSw3Eth1 = "s3-eth1";
    InterfaceIpAddress ia4 = new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"));
    Interface intfsw3eth1 = new Interface(Interface.NO_INTERFACE_NAME, s3Eth1, ImmutableList.of(ia4), MacAddress.valueOf("00:00:00:00:00:04"), VLAN10);
    configuredInterfaces.put(interfaceSw3Eth1, intfsw3eth1);
    String interfaceSw3Eth1intf2 = "s3-eth1_2";
    InterfaceIpAddress ia5 = new InterfaceIpAddress(IpAddress.valueOf("192.168.50.101"), IpPrefix.valueOf("192.168.50.0/24"));
    Interface intfsw3eth1intf2 = new Interface(Interface.NO_INTERFACE_NAME, s3Eth1, ImmutableList.of(ia5), MacAddress.valueOf("00:00:00:00:00:05"), VLAN20);
    configuredInterfaces.put(interfaceSw3Eth1intf2, intfsw3eth1intf2);
    expect(interfaceService.getInterfacesByPort(s1Eth1)).andReturn(Collections.singleton(intfsw1eth1)).anyTimes();
    expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.10.101"))).andReturn(Collections.singleton(intfsw1eth1)).anyTimes();
    expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.10.1"))).andReturn(intfsw1eth1).anyTimes();
    expect(interfaceService.getInterfacesByPort(s2Eth1)).andReturn(Collections.singleton(intfsw2eth1)).anyTimes();
    expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.20.101"))).andReturn(Collections.singleton(intfsw2eth1)).anyTimes();
    expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.20.1"))).andReturn(intfsw2eth1).anyTimes();
    expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.30.101"))).andReturn(Collections.singleton(intfsw2eth1intf2)).anyTimes();
    expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.30.1"))).andReturn(intfsw2eth1intf2).anyTimes();
    expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.40.101"))).andReturn(Collections.singleton(intfsw3eth1)).anyTimes();
    expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.40.1"))).andReturn(intfsw3eth1).anyTimes();
    expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.50.101"))).andReturn(Collections.singleton(intfsw3eth1intf2)).anyTimes();
    expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.50.1"))).andReturn(intfsw3eth1intf2).anyTimes();
    // Non-existent interface used during one of the tests
    expect(interfaceService.getInterfacesByPort(new ConnectPoint(DeviceId.deviceId("of:0000000000000100"), PortNumber.portNumber(1)))).andReturn(null).anyTimes();
    expect(interfaceService.getInterfaces()).andReturn(Sets.newHashSet(configuredInterfaces.values())).anyTimes();
    return configuredInterfaces;
}
Also used : HashMap(java.util.HashMap) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Interface(org.onosproject.net.intf.Interface) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress)

Aggregations

InterfaceIpAddress (org.onosproject.net.host.InterfaceIpAddress)28 Interface (org.onosproject.net.intf.Interface)21 ConnectPoint (org.onosproject.net.ConnectPoint)16 ArrayList (java.util.ArrayList)11 IpAddress (org.onlab.packet.IpAddress)9 MacAddress (org.onlab.packet.MacAddress)9 VlanId (org.onlab.packet.VlanId)9 DeviceId (org.onosproject.net.DeviceId)9 Ethernet (org.onlab.packet.Ethernet)5 IPv4 (org.onlab.packet.IPv4)5 PortNumber (org.onosproject.net.PortNumber)5 TrafficSelector (org.onosproject.net.flow.TrafficSelector)5 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 HashMultimap (com.google.common.collect.HashMultimap)4 Lists (com.google.common.collect.Lists)4 Sets (com.google.common.collect.Sets)4 Collections (java.util.Collections)4 List (java.util.List)4 Set (java.util.Set)4