Search in sources :

Example 1 with InterfaceService

use of org.onosproject.net.intf.InterfaceService in project onos by opennetworkinglab.

the class FibInstallerTest method setUp.

@Before
public void setUp() throws Exception {
    sSfibInstaller = new FibInstaller();
    sSfibInstaller.componentConfigService = createNiceMock(ComponentConfigService.class);
    ComponentContext mockContext = createNiceMock(ComponentContext.class);
    routerConfig = new TestRouterConfig();
    interfaceService = createMock(InterfaceService.class);
    networkConfigService = createMock(NetworkConfigService.class);
    networkConfigService.addListener(anyObject(NetworkConfigListener.class));
    expectLastCall().anyTimes();
    networkConfigRegistry = createMock(NetworkConfigRegistry.class);
    flowObjectiveService = createMock(FlowObjectiveService.class);
    applicationService = createNiceMock(ApplicationService.class);
    replay(applicationService);
    deviceService = new TestDeviceService();
    CoreService coreService = createNiceMock(CoreService.class);
    expect(coreService.registerApplication(anyString())).andReturn(APPID).anyTimes();
    replay(coreService);
    sSfibInstaller.networkConfigService = networkConfigService;
    sSfibInstaller.networkConfigRegistry = networkConfigRegistry;
    sSfibInstaller.interfaceService = interfaceService;
    sSfibInstaller.flowObjectiveService = flowObjectiveService;
    sSfibInstaller.applicationService = applicationService;
    sSfibInstaller.coreService = coreService;
    sSfibInstaller.routeService = new TestRouteService();
    sSfibInstaller.deviceService = deviceService;
    setUpNetworkConfigService();
    setUpInterfaceService();
    sSfibInstaller.activate(mockContext);
}
Also used : ComponentConfigService(org.onosproject.cfg.ComponentConfigService) ComponentContext(org.osgi.service.component.ComponentContext) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) CoreService(org.onosproject.core.CoreService) InterfaceService(org.onosproject.net.intf.InterfaceService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) ApplicationService(org.onosproject.app.ApplicationService) Before(org.junit.Before)

Example 2 with InterfaceService

use of org.onosproject.net.intf.InterfaceService in project onos by opennetworkinglab.

the class Dhcp6HandlerUtil method processLQ6PacketFromServer.

/**
 * process the LQ reply packet from dhcp server.
 *
 * @param defaultServerInfoList default server list
 * @param indirectServerInfoList default indirect server list
 * @param serverInterface server interface
 * @param interfaceService interface service
 * @param hostService host service
 * @param context packet context
 * @param receivedPacket server ethernet packet
 * @param recevingInterfaces set of server side interfaces
 * @return a packet ready to be sent to relevant output interface
 */
public static InternalPacket processLQ6PacketFromServer(List<DhcpServerInfo> defaultServerInfoList, List<DhcpServerInfo> indirectServerInfoList, Interface serverInterface, InterfaceService interfaceService, HostService hostService, PacketContext context, Ethernet receivedPacket, Set<Interface> recevingInterfaces) {
    // get dhcp6 header.
    Ethernet etherReply = (Ethernet) receivedPacket.clone();
    IPv6 ipv6Packet = (IPv6) etherReply.getPayload();
    UDP udpPacket = (UDP) ipv6Packet.getPayload();
    DHCP6 lq6Reply = (DHCP6) udpPacket.getPayload();
    // TODO: refactor
    ConnectPoint receivedFrom = context.inPacket().receivedFrom();
    DeviceId receivedFromDevice = receivedFrom.deviceId();
    DhcpServerInfo serverInfo;
    Ip6Address dhcpServerIp = null;
    ConnectPoint dhcpServerConnectPoint = null;
    MacAddress dhcpConnectMac = null;
    VlanId dhcpConnectVlan = null;
    Ip6Address dhcpGatewayIp = null;
    // todo: refactor
    Ip6Address indirectDhcpServerIp = null;
    ConnectPoint indirectDhcpServerConnectPoint = null;
    MacAddress indirectDhcpConnectMac = null;
    VlanId indirectDhcpConnectVlan = null;
    Ip6Address indirectDhcpGatewayIp = null;
    Ip6Address indirectRelayAgentIpFromCfg = null;
    if (!defaultServerInfoList.isEmpty()) {
        serverInfo = defaultServerInfoList.get(0);
        dhcpConnectMac = serverInfo.getDhcpConnectMac().orElse(null);
        dhcpGatewayIp = serverInfo.getDhcpGatewayIp6().orElse(null);
        dhcpServerIp = serverInfo.getDhcpServerIp6().orElse(null);
        dhcpServerConnectPoint = serverInfo.getDhcpServerConnectPoint().orElse(null);
        dhcpConnectVlan = serverInfo.getDhcpConnectVlan().orElse(null);
    }
    if (!indirectServerInfoList.isEmpty()) {
        serverInfo = indirectServerInfoList.get(0);
        indirectDhcpConnectMac = serverInfo.getDhcpConnectMac().orElse(null);
        indirectDhcpGatewayIp = serverInfo.getDhcpGatewayIp6().orElse(null);
        indirectDhcpServerIp = serverInfo.getDhcpServerIp6().orElse(null);
        indirectDhcpServerConnectPoint = serverInfo.getDhcpServerConnectPoint().orElse(null);
        indirectDhcpConnectVlan = serverInfo.getDhcpConnectVlan().orElse(null);
        indirectRelayAgentIpFromCfg = serverInfo.getRelayAgentIp6(receivedFromDevice).orElse(null);
    }
    Boolean directConnFlag = directlyConnected(lq6Reply);
    ConnectPoint inPort = context.inPacket().receivedFrom();
    if ((directConnFlag || indirectDhcpServerIp == null) && !inPort.equals(dhcpServerConnectPoint)) {
        log.warn("Receiving port {} is not the same as server connect point {} for direct or indirect-null", inPort, dhcpServerConnectPoint);
        return null;
    }
    if (!directConnFlag && indirectDhcpServerIp != null && !inPort.equals(indirectDhcpServerConnectPoint)) {
        log.warn("Receiving port {} is not the same as server connect point {} for indirect", inPort, indirectDhcpServerConnectPoint);
        return null;
    }
    Ip6Address nextHopIP = Ip6Address.valueOf(ipv6Packet.getDestinationAddress());
    // use hosts store to find out the next hop mac and connection point
    Set<Host> hosts = hostService.getHostsByIp(nextHopIP);
    Host host;
    if (!hosts.isEmpty()) {
        host = hosts.iterator().next();
    } else {
        log.warn("Host {} is not in store", nextHopIP);
        return null;
    }
    HostLocation hl = host.location();
    // iterator().next());
    String clientConnectionPointStr = hl.toString();
    ConnectPoint clientConnectionPoint = ConnectPoint.deviceConnectPoint(clientConnectionPointStr);
    VlanId originalPacketVlanId = VlanId.vlanId(etherReply.getVlanID());
    Interface iface;
    iface = interfaceService.getInterfacesByPort(clientConnectionPoint).stream().filter(iface1 -> interfaceContainsVlan(iface1, originalPacketVlanId)).findFirst().orElse(null);
    etherReply.setSourceMACAddress(iface.mac());
    etherReply.setDestinationMACAddress(host.mac());
    // workaround for a bug where core sends src port as 547 (server)
    udpPacket.setDestinationPort(UDP.DHCP_V6_SERVER_PORT);
    udpPacket.setPayload(lq6Reply);
    udpPacket.resetChecksum();
    ipv6Packet.setPayload(udpPacket);
    etherReply.setPayload(ipv6Packet);
    return InternalPacket.internalPacket(etherReply, clientConnectionPoint);
}
Also used : UDP(org.onlab.packet.UDP) HostLocation(org.onosproject.net.HostLocation) Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface) LoggerFactory(org.slf4j.LoggerFactory) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) Dhcp6ClientIdOption(org.onlab.packet.dhcp.Dhcp6ClientIdOption) Dhcp6RelayOption(org.onlab.packet.dhcp.Dhcp6RelayOption) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) Ethernet(org.onlab.packet.Ethernet) DhcpRelayCounters(org.onosproject.dhcprelay.store.DhcpRelayCounters) IpAddress(org.onlab.packet.IpAddress) BasePacket(org.onlab.packet.BasePacket) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) Ip6Address(org.onlab.packet.Ip6Address) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Dhcp6Option(org.onlab.packet.dhcp.Dhcp6Option) Set(java.util.Set) MsgType(org.onlab.packet.DHCP6.MsgType) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) UDP(org.onlab.packet.UDP) IPv6(org.onlab.packet.IPv6) DHCP6(org.onlab.packet.DHCP6) List(java.util.List) HexString(org.onlab.util.HexString) PacketContext(org.onosproject.net.packet.PacketContext) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) IPv6(org.onlab.packet.IPv6) DeviceId(org.onosproject.net.DeviceId) Host(org.onosproject.net.Host) HexString(org.onlab.util.HexString) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) Ip6Address(org.onlab.packet.Ip6Address) Ethernet(org.onlab.packet.Ethernet) HostLocation(org.onosproject.net.HostLocation) DHCP6(org.onlab.packet.DHCP6) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) VlanId(org.onlab.packet.VlanId) Interface(org.onosproject.net.intf.Interface)

Example 3 with InterfaceService

use of org.onosproject.net.intf.InterfaceService in project onos by opennetworkinglab.

the class InterfacesListCommand method doExecute.

@Override
protected void doExecute() {
    InterfaceService interfaceService = get(InterfaceService.class);
    List<Interface> interfaces = Lists.newArrayList(interfaceService.getInterfaces());
    Collections.sort(interfaces, Comparators.INTERFACES_COMPARATOR);
    interfaces.forEach(this::printInterface);
}
Also used : InterfaceService(org.onosproject.net.intf.InterfaceService) Interface(org.onosproject.net.intf.Interface)

Example 4 with InterfaceService

use of org.onosproject.net.intf.InterfaceService in project onos by opennetworkinglab.

the class HostMonitorTest method testMonitorIpv4HostDoesNotExist.

@Test
public void testMonitorIpv4HostDoesNotExist() throws Exception {
    HostManager hostManager = createMock(HostManager.class);
    DeviceId devId = DeviceId.deviceId("fake");
    Device device = createMock(Device.class);
    expect(device.id()).andReturn(devId).anyTimes();
    replay(device);
    PortNumber portNum = PortNumber.portNumber(1L);
    Port port = createMock(Port.class);
    expect(port.number()).andReturn(portNum).anyTimes();
    expect(port.isEnabled()).andReturn(true).anyTimes();
    replay(port);
    TestDeviceService deviceService = new TestDeviceService();
    deviceService.addDevice(device, Collections.singleton(port));
    ConnectPoint cp = new ConnectPoint(devId, portNum);
    expect(hostManager.getHostsByIp(TARGET_IPV4_ADDR)).andReturn(Collections.emptySet()).anyTimes();
    replay(hostManager);
    InterfaceService interfaceService = createMock(InterfaceService.class);
    expect(interfaceService.getMatchingInterfaces(TARGET_IPV4_ADDR)).andReturn(Collections.singleton(new Interface(Interface.NO_INTERFACE_NAME, cp, Collections.singletonList(IA1), sourceMac, VlanId.NONE))).anyTimes();
    replay(interfaceService);
    TestPacketService packetService = new TestPacketService();
    // Run the test
    hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService, deviceService);
    hostMonitor.addMonitoringFor(TARGET_IPV4_ADDR);
    hostMonitor.run();
    // Check that a packet was sent to our PacketService and that it has
    // the properties we expect
    assertEquals(2, packetService.packets.size());
    OutboundPacket packet = packetService.packets.get(0);
    // Check the output port is correct
    assertEquals(1, packet.treatment().immediate().size());
    Instruction instruction = packet.treatment().immediate().get(0);
    assertTrue(instruction instanceof OutputInstruction);
    OutputInstruction oi = (OutputInstruction) instruction;
    assertEquals(portNum, oi.port());
    // Check the output packet is correct (well the important bits anyway)
    final byte[] pktData = new byte[packet.data().remaining()];
    packet.data().get(pktData);
    Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length);
    assertEquals(Ethernet.VLAN_UNTAGGED, eth.getVlanID());
    ARP arp = (ARP) eth.getPayload();
    assertArrayEquals(SOURCE_IPV4_ADDR.toOctets(), arp.getSenderProtocolAddress());
    assertArrayEquals(sourceMac.toBytes(), arp.getSenderHardwareAddress());
    assertArrayEquals(TARGET_IPV4_ADDR.toOctets(), arp.getTargetProtocolAddress());
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) ConnectPoint(org.onosproject.net.ConnectPoint) OutboundPacket(org.onosproject.net.packet.OutboundPacket) InterfaceService(org.onosproject.net.intf.InterfaceService) Ethernet(org.onlab.packet.Ethernet) PortNumber(org.onosproject.net.PortNumber) Interface(org.onosproject.net.intf.Interface) ARP(org.onlab.packet.ARP) Test(org.junit.Test)

Example 5 with InterfaceService

use of org.onosproject.net.intf.InterfaceService in project onos by opennetworkinglab.

the class HostMonitorTest method testMonitorIpv4HostDoesNotExistWithVlan.

@Test
public void testMonitorIpv4HostDoesNotExistWithVlan() throws Exception {
    HostManager hostManager = createMock(HostManager.class);
    DeviceId devId = DeviceId.deviceId("fake");
    short vlan = 5;
    Device device = createMock(Device.class);
    expect(device.id()).andReturn(devId).anyTimes();
    replay(device);
    PortNumber portNum = PortNumber.portNumber(1L);
    Port port = createMock(Port.class);
    expect(port.number()).andReturn(portNum).anyTimes();
    expect(port.isEnabled()).andReturn(true).anyTimes();
    replay(port);
    TestDeviceService deviceService = new TestDeviceService();
    deviceService.addDevice(device, Collections.singleton(port));
    ConnectPoint cp = new ConnectPoint(devId, portNum);
    expect(hostManager.getHostsByIp(TARGET_IPV4_ADDR)).andReturn(Collections.emptySet()).anyTimes();
    replay(hostManager);
    InterfaceService interfaceService = createMock(InterfaceService.class);
    expect(interfaceService.getMatchingInterfaces(TARGET_IPV4_ADDR)).andReturn(Collections.singleton(new Interface(Interface.NO_INTERFACE_NAME, cp, Collections.singletonList(IA1), sourceMac, VlanId.vlanId(vlan)))).anyTimes();
    replay(interfaceService);
    TestPacketService packetService = new TestPacketService();
    // Run the test
    hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService, deviceService);
    hostMonitor.addMonitoringFor(TARGET_IPV4_ADDR);
    hostMonitor.run();
    // Check that a packet was sent to our PacketService and that it has
    // the properties we expect
    assertEquals(2, packetService.packets.size());
    OutboundPacket packet = packetService.packets.get(0);
    // Check the output port is correct
    assertEquals(1, packet.treatment().immediate().size());
    Instruction instruction = packet.treatment().immediate().get(0);
    assertTrue(instruction instanceof OutputInstruction);
    OutputInstruction oi = (OutputInstruction) instruction;
    assertEquals(portNum, oi.port());
    // Check the output packet is correct (well the important bits anyway)
    final byte[] pktData = new byte[packet.data().remaining()];
    packet.data().get(pktData);
    Ethernet eth = Ethernet.deserializer().deserialize(pktData, 0, pktData.length);
    assertEquals(vlan, eth.getVlanID());
    ARP arp = (ARP) eth.getPayload();
    assertArrayEquals(SOURCE_IPV4_ADDR.toOctets(), arp.getSenderProtocolAddress());
    assertArrayEquals(sourceMac.toBytes(), arp.getSenderHardwareAddress());
    assertArrayEquals(TARGET_IPV4_ADDR.toOctets(), arp.getTargetProtocolAddress());
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) ConnectPoint(org.onosproject.net.ConnectPoint) OutboundPacket(org.onosproject.net.packet.OutboundPacket) InterfaceService(org.onosproject.net.intf.InterfaceService) Ethernet(org.onlab.packet.Ethernet) PortNumber(org.onosproject.net.PortNumber) Interface(org.onosproject.net.intf.Interface) ARP(org.onlab.packet.ARP) Test(org.junit.Test)

Aggregations

InterfaceService (org.onosproject.net.intf.InterfaceService)8 Interface (org.onosproject.net.intf.Interface)6 Ethernet (org.onlab.packet.Ethernet)5 ConnectPoint (org.onosproject.net.ConnectPoint)5 DeviceId (org.onosproject.net.DeviceId)5 Test (org.junit.Test)4 Device (org.onosproject.net.Device)4 Port (org.onosproject.net.Port)4 PortNumber (org.onosproject.net.PortNumber)4 Instruction (org.onosproject.net.flow.instructions.Instruction)4 OutputInstruction (org.onosproject.net.flow.instructions.Instructions.OutputInstruction)4 OutboundPacket (org.onosproject.net.packet.OutboundPacket)4 IPv6 (org.onlab.packet.IPv6)3 ARP (org.onlab.packet.ARP)2 NeighborSolicitation (org.onlab.packet.ndp.NeighborSolicitation)2 CoreService (org.onosproject.core.CoreService)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1