Search in sources :

Example 6 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)

Example 7 with InterfaceService

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

the class HostMonitorTest method testMonitorIpv6HostDoesNotExistWithVlan.

@Test
public void testMonitorIpv6HostDoesNotExistWithVlan() 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_IPV6_ADDR)).andReturn(Collections.emptySet()).anyTimes();
    replay(hostManager);
    InterfaceService interfaceService = createMock(InterfaceService.class);
    expect(interfaceService.getMatchingInterfaces(TARGET_IPV6_ADDR)).andReturn(Collections.singleton(new Interface(Interface.NO_INTERFACE_NAME, cp, Collections.singletonList(IA2), sourceMac2, VlanId.vlanId(vlan)))).anyTimes();
    replay(interfaceService);
    TestPacketService packetService = new TestPacketService();
    // Run the test
    hostMonitor = new HostMonitor(packetService, hostManager, interfaceService, edgePortService, deviceService);
    hostMonitor.addMonitoringFor(TARGET_IPV6_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());
    IPv6 ipv6 = (IPv6) eth.getPayload();
    assertArrayEquals(SOURCE_IPV6_ADDR.toOctets(), ipv6.getSourceAddress());
    NeighborSolicitation ns = (NeighborSolicitation) ipv6.getPayload().getPayload();
    assertArrayEquals(sourceMac2.toBytes(), ns.getOptions().get(0).data());
    assertArrayEquals(TARGET_IPV6_ADDR.toOctets(), ns.getTargetAddress());
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) IPv6(org.onlab.packet.IPv6) 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) NeighborSolicitation(org.onlab.packet.ndp.NeighborSolicitation) PortNumber(org.onosproject.net.PortNumber) Interface(org.onosproject.net.intf.Interface) Test(org.junit.Test)

Example 8 with InterfaceService

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

the class AddPeerCommand method doExecute.

@Override
protected void doExecute() {
    peerAddress = IpAddress.valueOf(ip);
    NetworkConfigService configService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);
    BgpConfig config = configService.getConfig(appId, BgpConfig.class);
    if (config == null || config.bgpSpeakers().isEmpty()) {
        print(NO_CONFIGURATION);
        return;
    }
    BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name);
    if (speaker == null) {
        print(SPEAKER_NOT_FOUND, name);
        return;
    } else {
        if (speaker.isConnectedToPeer(peerAddress)) {
            // Peering already exists.
            return;
        }
    }
    InterfaceService interfaceService = get(InterfaceService.class);
    if (interfaceService.getMatchingInterface(peerAddress) == null) {
        print(NO_INTERFACE, ip);
        return;
    }
    addPeerToSpeakerConf(config);
    configService.applyConfig(appId, BgpConfig.class, config.node());
    print(PEER_ADD_SUCCESS);
}
Also used : BgpConfig(org.onosproject.routing.config.BgpConfig) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) InterfaceService(org.onosproject.net.intf.InterfaceService) CoreService(org.onosproject.core.CoreService) ApplicationId(org.onosproject.core.ApplicationId)

Example 9 with InterfaceService

use of org.onosproject.net.intf.InterfaceService in project trellis-control by opennetworkinglab.

the class DeviceConfigurationTest method setUp.

@Before
public void setUp() throws Exception {
    InterfaceService interfaceService;
    networkConfigService = null;
    NeighbourResolutionService neighbourResolutionService;
    SegmentRoutingManager srManager;
    // Mock device netcfg
    InputStream jsonStream = SegmentRoutingDeviceConfigTest.class.getResourceAsStream("/device.json");
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(jsonStream);
    SegmentRoutingDeviceConfig srDevConfig = new SegmentRoutingDeviceConfig();
    srDevConfig.init(DEV1, CONFIG_KEY, jsonNode, mapper, config -> {
    });
    BasicDeviceConfig basicDeviceConfig = new BasicDeviceConfig();
    basicDeviceConfig.init(DEV1, DEV1.toString(), JsonNodeFactory.instance.objectNode(), mapper, config -> {
    });
    // Mock interface netcfg
    jsonStream = InterfaceConfig.class.getResourceAsStream("/interface1.json");
    jsonNode = mapper.readTree(jsonStream);
    InterfaceConfig interfaceConfig1 = new InterfaceConfig();
    interfaceConfig1.init(CP1, CONFIG_KEY, jsonNode, mapper, config -> {
    });
    jsonStream = InterfaceConfig.class.getResourceAsStream("/interface2.json");
    jsonNode = mapper.readTree(jsonStream);
    InterfaceConfig interfaceConfig2 = new InterfaceConfig();
    interfaceConfig2.init(CP1, CONFIG_KEY, jsonNode, mapper, config -> {
    });
    jsonStream = BasicHostConfig.class.getResourceAsStream("/host1.json");
    jsonNode = mapper.readTree(jsonStream);
    BasicHostConfig hostConfig1 = new BasicHostConfig();
    hostConfig1.init(ROUTER_HOST, "basic", jsonNode, mapper, config -> {
    });
    networkConfigService = createMock(NetworkConfigRegistry.class);
    expect(networkConfigService.getSubjects(DeviceId.class, SegmentRoutingDeviceConfig.class)).andReturn(Sets.newHashSet(DEV1)).anyTimes();
    expect(networkConfigService.getConfig(DEV1, SegmentRoutingDeviceConfig.class)).andReturn(srDevConfig).anyTimes();
    expect(networkConfigService.addConfig(DEV1, BasicDeviceConfig.class)).andReturn(basicDeviceConfig).anyTimes();
    expect(networkConfigService.getConfig(DEV1, BasicDeviceConfig.class)).andReturn(basicDeviceConfig).anyTimes();
    expect(networkConfigService.getSubjects(ConnectPoint.class, InterfaceConfig.class)).andReturn(Sets.newHashSet(CP1, CP2)).anyTimes();
    expect(networkConfigService.getConfig(CP1, InterfaceConfig.class)).andReturn(interfaceConfig1).anyTimes();
    expect(networkConfigService.getConfig(CP2, InterfaceConfig.class)).andReturn(interfaceConfig2).anyTimes();
    expect(networkConfigService.applyConfig(eq(CP1), eq(InterfaceConfig.class), anyObject())).andReturn(interfaceConfig1).anyTimes();
    expect(networkConfigService.applyConfig(eq(CP2), eq(InterfaceConfig.class), anyObject())).andReturn(interfaceConfig2).anyTimes();
    expect(networkConfigService.getConfig(null, SegmentRoutingAppConfig.class)).andReturn(null).anyTimes();
    expect(networkConfigService.getConfig(ROUTER_HOST, BasicHostConfig.class)).andReturn(hostConfig1).anyTimes();
    expect(networkConfigService.applyConfig(eq(ROUTER_HOST), eq(BasicHostConfig.class), anyObject())).andReturn(hostConfig1).anyTimes();
    replay(networkConfigService);
    interfaceService = createMock(InterfaceService.class);
    expect(interfaceService.getInterfaces()).andReturn(INTERFACES).anyTimes();
    expect(interfaceService.getInterfacesByPort(CP1)).andReturn(Sets.newHashSet(INTF1)).anyTimes();
    expect(interfaceService.getInterfacesByPort(CP2)).andReturn(Sets.newHashSet(INTF2)).anyTimes();
    replay(interfaceService);
    neighbourResolutionService = createMock(NeighbourResolutionService.class);
    neighbourResolutionService.registerNeighbourHandler(anyObject(ConnectPoint.class), anyObject(), anyObject());
    expectLastCall().anyTimes();
    replay(neighbourResolutionService);
    srManager = new SegmentRoutingManager();
    srManager.interfaceService = interfaceService;
    srManager.cfgService = networkConfigService;
    srManager.neighbourResolutionService = neighbourResolutionService;
    devConfig = new DeviceConfiguration(srManager);
    devConfig.addSubnet(CP2, ROUTE1);
}
Also used : InputStream(java.io.InputStream) DeviceId(org.onosproject.net.DeviceId) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConnectPoint(org.onosproject.net.ConnectPoint) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig) BasicHostConfig(org.onosproject.net.config.basics.BasicHostConfig) InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) InterfaceService(org.onosproject.net.intf.InterfaceService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) SegmentRoutingManager(org.onosproject.segmentrouting.SegmentRoutingManager) DeviceConfiguration(org.onosproject.segmentrouting.DeviceConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NeighbourResolutionService(org.onosproject.net.neighbour.NeighbourResolutionService) Before(org.junit.Before)

Example 10 with InterfaceService

use of org.onosproject.net.intf.InterfaceService in project trellis-control by opennetworkinglab.

the class PwaasUtilTest method setUp.

@Before
public void setUp() {
    DeviceService deviceService = createNiceMock(DeviceService.class);
    InterfaceService intfService = createNiceMock(InterfaceService.class);
    TestUtils.setField(PwaasUtil.class, "deviceService", deviceService);
    TestUtils.setField(PwaasUtil.class, "intfService", intfService);
    expect(deviceService.getDevice(DID1)).andReturn(D1).anyTimes();
    expect(deviceService.getDevice(DID2)).andReturn(D2).anyTimes();
    expect(deviceService.getPort(CP11)).andReturn(P11).anyTimes();
    expect(deviceService.getPort(CP12)).andReturn(P12).anyTimes();
    expect(deviceService.getPort(CP21)).andReturn(P21).anyTimes();
    expect(deviceService.getPort(CP22)).andReturn(P22).anyTimes();
    expect(intfService.getInterfacesByPort(CP11)).andReturn(Sets.newHashSet(I11)).anyTimes();
    expect(intfService.getInterfacesByPort(CP12)).andReturn(Sets.newHashSet(I12)).anyTimes();
    expect(intfService.getInterfacesByPort(CP21)).andReturn(Sets.newHashSet(I21)).anyTimes();
    expect(intfService.getInterfacesByPort(CP22)).andReturn(Sets.newHashSet(I22)).anyTimes();
    replay(deviceService);
    replay(intfService);
}
Also used : InterfaceService(org.onosproject.net.intf.InterfaceService) DeviceService(org.onosproject.net.device.DeviceService) Before(org.junit.Before)

Aggregations

InterfaceService (org.onosproject.net.intf.InterfaceService)10 ConnectPoint (org.onosproject.net.ConnectPoint)6 DeviceId (org.onosproject.net.DeviceId)6 Interface (org.onosproject.net.intf.Interface)6 Ethernet (org.onlab.packet.Ethernet)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 Before (org.junit.Before)3 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 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1