Search in sources :

Example 76 with Port

use of org.onosproject.net.Port 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 77 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class FlowStatisticManager method loadTopnByType.

@Override
public Map<ConnectPoint, List<FlowEntryWithLoad>> loadTopnByType(Device device, FlowEntry.FlowLiveType liveType, Instruction.Type instType, int topn) {
    checkPermission(STATISTIC_READ);
    Map<ConnectPoint, List<FlowEntryWithLoad>> allLoad = new TreeMap<>(Comparators.CONNECT_POINT_COMPARATOR);
    if (device == null) {
        return allLoad;
    }
    List<Port> ports = new ArrayList<>(deviceService.getPorts(device.id()));
    for (Port port : ports) {
        ConnectPoint cp = new ConnectPoint(device.id(), port.number());
        List<FlowEntryWithLoad> fel = loadTopnPortInternal(cp, liveType, instType, topn);
        allLoad.put(cp, fel);
    }
    return allLoad;
}
Also used : SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) TypedFlowEntryWithLoad(org.onosproject.net.statistic.TypedFlowEntryWithLoad) FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) Port(org.onosproject.net.Port) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 78 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class ResourceDeviceListener method queryBandwidth.

/**
 * Query bandwidth capacity on a port.
 *
 * @param did {@link DeviceId}
 * @param number {@link PortNumber}
 * @return bandwidth capacity
 */
private Optional<Bandwidth> queryBandwidth(DeviceId did, PortNumber number) {
    // Check and use netcfg first.
    ConnectPoint cp = new ConnectPoint(did, number);
    BandwidthCapacity config = netcfgService.getConfig(cp, BandwidthCapacity.class);
    if (config != null) {
        log.trace("Registering configured bandwidth {} for {}/{}", config.capacity(), did, number);
        return Optional.of(config.capacity());
    }
    // populate bandwidth value, assuming portSpeed == bandwidth
    Port port = deviceService.getPort(did, number);
    if (port != null) {
        return Optional.of(Bandwidth.mbps(port.portSpeed()));
    }
    return Optional.empty();
}
Also used : BandwidthCapacity(org.onosproject.net.config.basics.BandwidthCapacity) Port(org.onosproject.net.Port) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 79 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class DefaultKubevirtNodeHandler method isDeviceCreatedStateDone.

private boolean isDeviceCreatedStateDone(KubevirtNode node) {
    try {
        // we need to wait a while, in case tunneling ports
        // creation requires some time
        sleep(SLEEP_MID_MS);
    } catch (InterruptedException e) {
        log.error("Exception caused during init state checking...");
    }
    if (node.dataIp() != null && !isIntfEnabled(node, VXLAN)) {
        log.warn("VXLAN interface is not enabled!");
        return false;
    }
    if (node.dataIp() != null && !isIntfEnabled(node, GRE)) {
        log.warn("GRE interface is not enabled!");
        return false;
    }
    if (node.dataIp() != null && !isIntfEnabled(node, GENEVE)) {
        log.warn("GENEVE interface is not enabled!");
        return false;
    }
    for (KubevirtPhyInterface phyIntf : node.phyIntfs()) {
        if (phyIntf == null) {
            log.warn("Physnet interface is invalid");
            return false;
        }
        try {
            // we need to wait a while, in case tunneling ports
            // creation requires some time
            sleep(SLEEP_LONG_MS);
        } catch (InterruptedException e) {
            log.error("Exception caused during init state checking...");
        }
        String patchPortName = structurePortName(INTEGRATION_TO_PHYSICAL_PREFIX + phyIntf.network());
        if (node.type() == WORKER) {
            String bridgeName = BRIDGE_PREFIX + phyIntf.network();
            if (!(hasPhyBridge(node, bridgeName) && hasPhyPatchPort(node, patchPortName) && hasPhyIntf(node, phyIntf.intf()))) {
                log.warn("PhyBridge {}", hasPhyBridge(node, bridgeName));
                log.warn("hasPhyPatchPort {}", hasPhyPatchPort(node, patchPortName));
                log.warn("hasPhyIntf {}", hasPhyIntf(node, phyIntf.intf()));
                return false;
            }
        } else {
            // In case node type is GATEWAY, we create physical bridges connected to the contoller.
            // By doing so, ONOS immediately recognizes the status of physical interface and performs RM procedures.
            Port phyIntfPort = deviceService.getPorts(phyIntf.physBridge()).stream().filter(port -> port.annotations().value(PORT_NAME).equals(phyIntf.intf())).findAny().orElse(null);
            if (phyIntfPort == null) {
                log.warn("There's no connected physical port {} on physical device {}", phyIntf.intf(), phyIntf.physBridge());
            }
            if (!(deviceService.isAvailable(phyIntf.physBridge()) && hasPhyPatchPort(node, patchPortName) && hasPhyIntf(node, phyIntf.intf()) && phyIntfPort.isEnabled())) {
                log.warn("PhysBridge {}", deviceService.isAvailable(phyIntf.physBridge()));
                log.warn("hasPhyPatchPort {}", hasPhyPatchPort(node, patchPortName));
                log.warn("hasPhyIntf {}", hasPhyIntf(node, phyIntf.intf()));
                log.warn("physical interface port {}", phyIntfPort.isEnabled());
                return false;
            }
        }
    }
    if (node.type() == GATEWAY) {
        if (!(hasPhyIntf(node, INTEGRATION_TO_TUNNEL) && hasPhyIntf(node, TUNNEL_TO_INTEGRATION))) {
            log.warn("IntToTunPort {}", hasPhyIntf(node, INTEGRATION_TO_TUNNEL));
            log.warn("TunToIntPort {}", hasPhyIntf(node, TUNNEL_TO_INTEGRATION));
            return false;
        }
    }
    return true;
}
Also used : KubevirtPhyInterface(org.onosproject.kubevirtnode.api.KubevirtPhyInterface) TpPort.tpPort(org.onlab.packet.TpPort.tpPort) Port(org.onosproject.net.Port)

Example 80 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class DefaultKubevirtNode method tunnelPort.

private PortNumber tunnelPort(String tunnelType) {
    if (dataIp == null) {
        return null;
    }
    DeviceService deviceService = DefaultServiceDirectory.getService(DeviceService.class);
    Port port = deviceService.getPorts(tunBridge).stream().filter(p -> p.isEnabled() && Objects.equals(p.annotations().value(PORT_NAME), tunnelType)).findAny().orElse(null);
    return port != null ? port.number() : null;
}
Also used : Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService)

Aggregations

Port (org.onosproject.net.Port)200 DeviceService (org.onosproject.net.device.DeviceService)92 PortNumber (org.onosproject.net.PortNumber)85 ConnectPoint (org.onosproject.net.ConnectPoint)78 DeviceId (org.onosproject.net.DeviceId)76 Device (org.onosproject.net.Device)63 List (java.util.List)51 Set (java.util.Set)47 Optional (java.util.Optional)43 DefaultPort (org.onosproject.net.DefaultPort)38 Logger (org.slf4j.Logger)38 ArrayList (java.util.ArrayList)36 Collectors (java.util.stream.Collectors)35 Collections (java.util.Collections)34 Collection (java.util.Collection)33 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)33 Test (org.junit.Test)31 Ethernet (org.onlab.packet.Ethernet)31 Map (java.util.Map)29 Sets (com.google.common.collect.Sets)28