Search in sources :

Example 51 with Interface

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());
}
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 52 with Interface

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");
}
Also used : InterfaceAdminService(org.onosproject.net.intf.InterfaceAdminService) MacAddress(org.onlab.packet.MacAddress) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) VlanId(org.onlab.packet.VlanId) Interface(org.onosproject.net.intf.Interface)

Example 53 with Interface

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;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ConfigException(org.onosproject.net.config.ConfigException) MacAddress(org.onlab.packet.MacAddress) Interface(org.onosproject.net.intf.Interface) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) VlanId(org.onlab.packet.VlanId)

Example 54 with Interface

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));
}
Also used : InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) IpAddress(org.onlab.packet.IpAddress) Interface(org.onosproject.net.intf.Interface) Test(org.junit.Test)

Example 55 with Interface

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;
}
Also used : ConnectPoint(org.onosproject.net.ConnectPoint) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Interface(org.onosproject.net.intf.Interface)

Aggregations

Interface (org.onosproject.net.intf.Interface)92 ConnectPoint (org.onosproject.net.ConnectPoint)51 MacAddress (org.onlab.packet.MacAddress)35 VlanId (org.onlab.packet.VlanId)34 InterfaceIpAddress (org.onosproject.net.host.InterfaceIpAddress)32 Ethernet (org.onlab.packet.Ethernet)28 IpAddress (org.onlab.packet.IpAddress)28 ArrayList (java.util.ArrayList)26 DeviceId (org.onosproject.net.DeviceId)26 Host (org.onosproject.net.Host)25 InterfaceService (org.onosproject.net.intf.InterfaceService)25 Logger (org.slf4j.Logger)25 Set (java.util.Set)23 TrafficSelector (org.onosproject.net.flow.TrafficSelector)23 LoggerFactory (org.slf4j.LoggerFactory)23 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)22 Test (org.junit.Test)21 ApplicationId (org.onosproject.core.ApplicationId)21 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)20 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)20