use of org.onosproject.net.intf.Interface 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.Interface in project onos by opennetworkinglab.
the class InterfaceAddCommand method doExecute.
@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");
}
use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.
the class InterfaceConfig method getInterfaces.
/**
* 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;
}
use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.
the class InterfaceManagerTest method testGetMatchingInterface.
@Test
public void testGetMatchingInterface() throws Exception {
IpAddress ip = Ip4Address.valueOf("192.168.1.100");
Interface matchingIntf = createInterface(1);
assertEquals(matchingIntf, interfaceManager.getMatchingInterface(ip));
// Searching for an IP with no match should return null
ip = Ip4Address.valueOf("1.1.1.1");
assertNull(interfaceManager.getMatchingInterface(ip));
}
use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.
the class InterfaceManagerTest method createInterface.
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;
}
Aggregations