Search in sources :

Example 86 with PortNumber

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

the class GossipDeviceStoreTest method testGetPorts.

@Test
public final void testGetPorts() {
    putDevice(DID1, SW1);
    putDevice(DID2, SW1);
    List<PortDescription> pds = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).build(), DefaultPortDescription.builder().withPortNumber(P2).isEnabled(true).build());
    deviceStore.updatePorts(PID, DID1, pds);
    Set<PortNumber> expectedPorts = Sets.newHashSet(P1, P2);
    List<Port> ports = deviceStore.getPorts(DID1);
    for (Port port : ports) {
        assertTrue("Port is enabled", port.isEnabled());
        assertTrue("PortNumber is one of expected", expectedPorts.remove(port.number()));
    }
    assertTrue("Event for all expectedport appeared", expectedPorts.isEmpty());
    assertTrue("DID2 has no ports", deviceStore.getPorts(DID2).isEmpty());
}
Also used : Port(org.onosproject.net.Port) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) PortNumber(org.onosproject.net.PortNumber) Test(org.junit.Test)

Example 87 with PortNumber

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

the class GossipDeviceStoreTest method testUpdatePorts.

@Test
public final void testUpdatePorts() {
    putDevice(DID1, SW1);
    List<PortDescription> pds = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).build(), DefaultPortDescription.builder().withPortNumber(P2).isEnabled(true).build());
    Capture<InternalDeviceEvent> message = Capture.newInstance();
    Capture<MessageSubject> subject = Capture.newInstance();
    Capture<Function<InternalDeviceEvent, byte[]>> encoder = Capture.newInstance();
    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
    List<DeviceEvent> events = deviceStore.updatePorts(PID, DID1, pds);
    verify(clusterCommunicator);
    // TODO: verify broadcast message
    assertTrue(message.hasCaptured());
    Set<PortNumber> expectedPorts = Sets.newHashSet(P1, P2);
    for (DeviceEvent event : events) {
        assertEquals(PORT_ADDED, event.type());
        assertDevice(DID1, SW1, event.subject());
        assertTrue("PortNumber is one of expected", expectedPorts.remove(event.port().number()));
        assertTrue("Port is enabled", event.port().isEnabled());
    }
    assertTrue("Event for all expectedport appeared", expectedPorts.isEmpty());
    List<PortDescription> pds2 = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(false).build(), DefaultPortDescription.builder().withPortNumber(P2).isEnabled(true).build(), DefaultPortDescription.builder().withPortNumber(P3).isEnabled(true).build());
    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
    events = deviceStore.updatePorts(PID, DID1, pds2);
    verify(clusterCommunicator);
    // TODO: verify broadcast message
    assertTrue(message.hasCaptured());
    assertFalse("event should be triggered", events.isEmpty());
    for (DeviceEvent event : events) {
        PortNumber num = event.port().number();
        if (P1.equals(num)) {
            assertEquals(PORT_UPDATED, event.type());
            assertDevice(DID1, SW1, event.subject());
            assertFalse("Port is disabled", event.port().isEnabled());
        } else if (P2.equals(num)) {
            fail("P2 event not expected.");
        } else if (P3.equals(num)) {
            assertEquals(PORT_ADDED, event.type());
            assertDevice(DID1, SW1, event.subject());
            assertTrue("Port is enabled", event.port().isEnabled());
        } else {
            fail("Unknown port number encountered: " + num);
        }
    }
    List<PortDescription> pds3 = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(false).build(), DefaultPortDescription.builder().withPortNumber(P2).isEnabled(true).build());
    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
    events = deviceStore.updatePorts(PID, DID1, pds3);
    verify(clusterCommunicator);
    // TODO: verify broadcast message
    assertTrue(message.hasCaptured());
    assertFalse("event should be triggered", events.isEmpty());
    for (DeviceEvent event : events) {
        PortNumber num = event.port().number();
        if (P1.equals(num)) {
            fail("P1 event not expected.");
        } else if (P2.equals(num)) {
            fail("P2 event not expected.");
        } else if (P3.equals(num)) {
            assertEquals(PORT_REMOVED, event.type());
            assertDevice(DID1, SW1, event.subject());
            assertTrue("Port was enabled", event.port().isEnabled());
        } else {
            fail("Unknown port number encountered: " + num);
        }
    }
}
Also used : BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) DeviceEvent(org.onosproject.net.device.DeviceEvent) MessageSubject(org.onosproject.store.cluster.messaging.MessageSubject) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) PortNumber(org.onosproject.net.PortNumber) Test(org.junit.Test)

Example 88 with PortNumber

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

the class DistributedStatisticStore method buildConnectPoint.

private ConnectPoint buildConnectPoint(FlowRule rule) {
    PortNumber port = getOutput(rule);
    if (port == null) {
        return null;
    }
    ConnectPoint cp = new ConnectPoint(rule.deviceId(), port);
    return cp;
}
Also used : PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 89 with PortNumber

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

the class OpenConfigGnmiDeviceDescriptionDiscovery method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    if (!setupBehaviour("discoverPortDetails()")) {
        return Collections.emptyList();
    }
    log.debug("Discovering port details on device {}", handler().data().deviceId());
    final GetResponse response = Futures.getUnchecked(client.get(buildPortStateRequest()));
    final Map<String, DefaultPortDescription.Builder> ports = Maps.newHashMap();
    final Map<String, DefaultAnnotations.Builder> annotations = Maps.newHashMap();
    final Map<String, PortNumber> portIds = Maps.newHashMap();
    // Creates port descriptions with port name and port number
    response.getNotificationList().forEach(notification -> {
        notification.getUpdateList().forEach(update -> {
            // /interfaces/interface[name=ifName]/state/...
            final String ifName = update.getPath().getElem(1).getKeyMap().get("name");
            if (!ports.containsKey(ifName)) {
                ports.put(ifName, DefaultPortDescription.builder());
                annotations.put(ifName, DefaultAnnotations.builder());
            }
            final DefaultPortDescription.Builder builder = ports.get(ifName);
            final DefaultAnnotations.Builder annotationsBuilder = annotations.get(ifName);
            parseInterfaceInfo(update, ifName, builder, annotationsBuilder, portIds);
        });
    });
    final List<PortDescription> portDescriptionList = Lists.newArrayList();
    ports.forEach((key, value) -> {
        // For devices not providing last-change, we set it to 0
        final DefaultAnnotations.Builder annotationsBuilder = annotations.get(key);
        if (!annotationsBuilder.build().keys().contains(LAST_CHANGE)) {
            annotationsBuilder.set(LAST_CHANGE, String.valueOf(0));
        }
        /* Override port number if read port-id is enabled
               and /interfaces/interface/state/id is available */
        if (readPortId() && portIds.containsKey(key)) {
            value.withPortNumber(portIds.get(key));
        }
        DefaultAnnotations annotation = annotations.get(key).build();
        portDescriptionList.add(value.annotations(annotation).build());
    });
    return portDescriptionList;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) GetResponse(gnmi.Gnmi.GetResponse) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) PortNumber(org.onosproject.net.PortNumber)

Example 90 with PortNumber

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

the class OpenstackVtapManager method setOutputTable.

private void setOutputTable(DeviceId deviceId, Mode mode, IpAddress serverIp, boolean install) {
    log.debug("setOutputTable[{}]: deviceId={}, mode={}, serverIp={}", install ? "add" : "remove", deviceId, mode, serverIp);
    if (deviceId == null) {
        return;
    }
    switch(mode) {
        case GRE:
        case VXLAN:
            String tunnelName = getTunnelName(mode);
            PortNumber vtapPort = portNumber(deviceId, tunnelName);
            if (vtapPort != null) {
                for (int idx = 0; idx < VTAP_TABLES.length; idx++) {
                    setOutputTableForTunnel(deviceId, VTAP_TABLES[idx][VTAP_TABLE_OUTPUT_IDX], vtapPort, serverIp, install);
                }
            } else {
                log.warn("Vtap tunnel port {} doesn't exist", tunnelName);
            }
            break;
        default:
            log.warn("Invalid vtap network mode {}", mode);
            break;
    }
}
Also used : PortNumber(org.onosproject.net.PortNumber)

Aggregations

PortNumber (org.onosproject.net.PortNumber)336 DeviceId (org.onosproject.net.DeviceId)136 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)109 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)103 ConnectPoint (org.onosproject.net.ConnectPoint)82 TrafficSelector (org.onosproject.net.flow.TrafficSelector)80 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)74 Port (org.onosproject.net.Port)67 ArrayList (java.util.ArrayList)64 Set (java.util.Set)64 List (java.util.List)59 Logger (org.slf4j.Logger)58 Collectors (java.util.stream.Collectors)51 DeviceService (org.onosproject.net.device.DeviceService)49 VlanId (org.onlab.packet.VlanId)42 MacAddress (org.onlab.packet.MacAddress)41 Device (org.onosproject.net.Device)40 FlowRule (org.onosproject.net.flow.FlowRule)40 Optional (java.util.Optional)39 Sets (com.google.common.collect.Sets)35