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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations