org.onosproject.net.Port Java Examples

The following examples show how to use org.onosproject.net.Port. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultTributarySlotQuery.java    From onos with Apache License 2.0 6 votes vote down vote up
private Set<TributarySlot> queryOchTributarySlots(Port ochPort) {
    OduSignalType signalType = null;
    if (ochPort instanceof OchPort) {
        signalType = ((OchPort) ochPort).signalType();
    } else {
        log.warn("{} was not an OchPort", ochPort);
        return Collections.emptySet();
    }

    switch (signalType) {
        case ODU2:
            return ENTIRE_ODU2_TRIBUTARY_SLOTS;
        case ODU4:
            return ENTIRE_ODU4_TRIBUTARY_SLOTS;
        default:
            log.error("Unsupported signal type {} for {}", signalType, ochPort);
            return Collections.emptySet();
    }
}
 
Example #2
Source File: FlowStatisticManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Map<ConnectPoint, SummaryFlowEntryWithLoad> loadSummary(Device device) {
    checkPermission(STATISTIC_READ);

    Map<ConnectPoint, SummaryFlowEntryWithLoad> summaryLoad =
                                    new TreeMap<>(Comparators.CONNECT_POINT_COMPARATOR);

    if (device == null) {
        return summaryLoad;
    }

    List<Port> ports = new ArrayList<>(deviceService.getPorts(device.id()));

    for (Port port : ports) {
        ConnectPoint cp = new ConnectPoint(device.id(), port.number());
        SummaryFlowEntryWithLoad sfe = loadSummaryPortInternal(cp);
        summaryLoad.put(cp, sfe);
    }

    return summaryLoad;
}
 
Example #3
Source File: PortCodec.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Note: Result of {@link Port#element()} returned Port object,
 *       is not a full Device object.
 *       Only it's DeviceId can be used.
 */
@Override
public Port decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }

    DeviceId did = DeviceId.deviceId(json.get(ELEMENT).asText());
    Device device = new DummyDevice(did);
    PortNumber number = portNumber(json.get(PORT_NAME).asText());
    boolean isEnabled = json.get(IS_ENABLED).asBoolean();
    Type type = Type.valueOf(json.get(TYPE).asText().toUpperCase());
    long portSpeed = json.get(PORT_SPEED).asLong();
    Annotations annotations = extractAnnotations(json, context);

    return new DefaultPort(device, number, isEnabled, type, portSpeed, annotations);
}
 
Example #4
Source File: TroubleshootLoadSnapshotCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void loadDeviceNib() {
    DeviceService deviceService = get(DeviceService.class);
    Map<Device, Set<Port>> devicePortMap = new HashMap<>();

    Lists.newArrayList(deviceService.getDevices().iterator())
            .forEach(device -> {
                // current DeviceNib impl. checks the availability of devices from their annotations
                DefaultAnnotations annotations = DefaultAnnotations.builder()
                        .set("available", String.valueOf(deviceService.isAvailable(device.id()))).build();
                DefaultDevice annotated = new DefaultDevice(device.providerId(), device.id(), device.type(),
                        device.manufacturer(), device.hwVersion(), device.swVersion(), device.serialNumber(),
                        device.chassisId(), annotations);
                devicePortMap.put(annotated, Sets.newHashSet(deviceService.getPorts(device.id())));
            });

    DeviceNib deviceNib = DeviceNib.getInstance();
    deviceNib.setDevicePortMap(devicePortMap);
}
 
Example #5
Source File: SimpleDeviceStore.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public DeviceEvent removeDevice(DeviceId deviceId) {
    Map<ProviderId, DeviceDescriptions> descs = getOrCreateDeviceDescriptions(deviceId);
    synchronized (descs) {
        Device device = devices.remove(deviceId);
        // should DEVICE_REMOVED carry removed ports?
        Map<PortNumber, Port> ports = devicePorts.get(deviceId);
        if (ports != null) {
            ports.clear();
        }
        availableDevices.remove(deviceId);
        descs.clear();
        return device == null ? null :
                new DeviceEvent(DEVICE_REMOVED, device, null);
    }
}
 
Example #6
Source File: LldpLinkProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Checks that discovery on reconfigured port are properly restarted.
 */
@Test
public void portSuppressedByPortConfig() {

    // add device in stub DeviceService without suppression configured
    deviceService.putDevice(device(DID3));
    deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID3));

    // suppressed port added to non-suppressed device
    final long portno3 = 3L;
    final Port port3 = port(DID3, portno3, true,
                            DefaultAnnotations.builder()
                                    .set(LldpLinkProvider.NO_LLDP, "true")
                                    .build());
    deviceService.putPorts(DID3, port3);
    deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID3, port3));

    // discovery helper should be there turned on
    assertFalse("Discoverer is expected to start", provider.discoverers.get(DID3).isStopped());
    assertFalse("Discoverer should not contain the port there",
                provider.discoverers.get(DID3).containsPort(portno3));
}
 
Example #7
Source File: SegmentRoutingManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processPortUpdatedInternal(Device device, Port port) {
    if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
        log.warn("Device configuration uploading. Not handling port event for"
                + "dev: {} port: {}", device.id(), port.number());
        return;
    }

    if (interfaceService.isConfigured(new ConnectPoint(device.id(), port.number()))) {
        lastEdgePortEvent = Instant.now();
    }

    if (!mastershipService.isLocalMaster(device.id()))  {
        log.debug("Not master for dev:{} .. not handling port updated event"
                + "for port {}", device.id(), port.number());
        return;
    }
    processPortUpdated(device.id(), port);
}
 
Example #8
Source File: OpenFlowDeviceProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Build a portDescription from a given Ethernet port description.
 *
 * @param port the port to build from.
 * @return portDescription for the port.
 */
private PortDescription buildPortDescription(OFPortDesc port) {
    if (port.getVersion().wireVersion >= OFVersion.OF_14.getWireVersion()) {
        return buildPortDescription14(port);
    }
    PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
    boolean enabled =
            !port.getState().contains(OFPortState.LINK_DOWN) &&
                    !port.getConfig().contains(OFPortConfig.PORT_DOWN);
    Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER;
    boolean adminDown = port.getConfig().contains(OFPortConfig.PORT_DOWN);
    SparseAnnotations annotations = makePortAnnotation(port.getName(),
                                                       port.getHwAddr().toString(),
                                                       adminDown).build();
    return DefaultPortDescription.builder()
            .withPortNumber(portNo)
            .isEnabled(enabled)
            .type(type)
            .portSpeed(portSpeed(port))
            .annotations(annotations)
            .build();
}
 
Example #9
Source File: OpticalPortOperatorTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigPortName() {
    opc.portType(Port.Type.ODUCLT)
        .portNumberName(PORT_NUMBER)
        .portName(CFG_PORT_NAME);

    PortDescription res;
    // full desc + opc with name
    res = oper.combine(CP, N_DESC);
    assertEquals("Configured port name expected",
                 CFG_PORT_NAME, res.portNumber().name());
    assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT));

    res = oper.combine(CP, U_DESC);
    assertEquals("Configured port name expected",
                 CFG_PORT_NAME, res.portNumber().name());
    assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT));
}
 
Example #10
Source File: GossipDeviceStoreTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #11
Source File: PcepTopologyProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
private List<PortDescription> buildPortDescriptions(PcepDpid dpid,
                                                    Port port) {

    List<PortDescription> portList;

    if (portMap.containsKey(dpid.value())) {
        portList = portMap.get(dpid.value());
    } else {
        portList = new ArrayList<>();
    }
    if (port != null) {
        SparseAnnotations annotations = DefaultAnnotations.builder()
                .putAll(port.annotations()).build();
        portList.add(DefaultPortDescription.builder()
                .withPortNumber(port.number())
                .isEnabled(port.isEnabled())
                .type(port.type())
                .portSpeed(port.portSpeed())
                .annotations(annotations)
                .build());
    }

    portMap.put(dpid.value(), portList);
    return portList;
}
 
Example #12
Source File: DefaultTributarySlotQuery.java    From onos with Apache License 2.0 6 votes vote down vote up
private Set<TributarySlot> queryOtuTributarySlots(Port otuPort) {
    OtuSignalType signalType = null;
    if (otuPort instanceof OtuPort) {
        signalType = ((OtuPort) otuPort).signalType();
    } else {
        log.warn("{} was not an OtuPort", otuPort);
        return Collections.emptySet();
    }

    switch (signalType) {
        case OTU2:
            return ENTIRE_ODU2_TRIBUTARY_SLOTS;
        case OTU4:
            return ENTIRE_ODU4_TRIBUTARY_SLOTS;
        default:
            log.error("Unsupported signal type {} for {}", signalType, otuPort);
            return Collections.emptySet();
    }
}
 
Example #13
Source File: OFOpticalSwitch13LambdaQuery.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Set<OchSignal> queryLambdas(PortNumber port) {
    DeviceService deviceService = opticalView(this.handler().get(DeviceService.class));
    Port p = deviceService.getPort(this.data().deviceId(), port);

    // Only OMS ports expose lambda resources
    if (p == null || !p.type().equals(Port.Type.OMS)) {
        return Collections.emptySet();
    }

    short lambdaCount = ((OmsPort) p).totalChannels();
    // OMS ports expose 'lambdaCount' fixed grid lambdas of 50GHz width, starting from min-frequency 191.7 THz.
    return IntStream.rangeClosed(1, lambdaCount)
            .mapToObj(x -> OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, x))
            .collect(GuavaCollectors.toImmutableSet());
}
 
Example #14
Source File: OpticalOduIntentCompilerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public List<Port> getPorts(DeviceId deviceId) {
    if (deviceId.equals(deviceId(DEV1))) {
        return ImmutableList.of((Port) D1P1, (Port) D1P2, (Port) D1P3);
    }

    if (deviceId.equals(deviceId(DEV2))) {
        return ImmutableList.of((Port) D2P1, (Port) D2P2);
    }

    if (deviceId.equals(deviceId(DEV3))) {
        return ImmutableList.of((Port) D3P1, (Port) D3P2, (Port) D3P3);
    }

    return Collections.emptyList();
}
 
Example #15
Source File: OpenstackSwitchingPhysicalHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isRelevant(DeviceEvent event) {
    Port port = event.port();
    if (port == null) {
        return false;
    }

    OpenstackNode osNode = osNodeService.node(event.subject().id());
    if (osNode == null) {
        return false;
    }

    Set<String> intPatchPorts = osNode.phyIntfs().stream()
            .map(pi -> structurePortName(INTEGRATION_TO_PHYSICAL_PREFIX
                    + pi.network())).collect(Collectors.toSet());
    String portName = port.annotations().value(PORT_NAME);

    return intPatchPorts.contains(portName);
}
 
Example #16
Source File: SimpleDeviceStoreTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Test
public final void testGetPort() {
    putDevice(DID1, SW1);
    putDevice(DID2, SW1);
    List<PortDescription> pds = Arrays.asList(
            DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).build(),
            DefaultPortDescription.builder().withPortNumber(P2).isEnabled(false).build()
            );
    deviceStore.updatePorts(PID, DID1, pds);

    Port port1 = deviceStore.getPort(DID1, P1);
    assertEquals(P1, port1.number());
    assertTrue("Port is enabled", port1.isEnabled());

    Port port2 = deviceStore.getPort(DID1, P2);
    assertEquals(P2, port2.number());
    assertFalse("Port is disabled", port2.isEnabled());

    Port port3 = deviceStore.getPort(DID1, P3);
    assertNull("P3 not expected", port3);
}
 
Example #17
Source File: RoadmUtil.java    From onos with Apache License 2.0 6 votes vote down vote up
public static OchSignal createOchSignalFromWavelength(double wavelength, DeviceService deviceService,
                                                      DeviceId deviceId, PortNumber portNumber) {
    if (wavelength == 0L) {
        return null;
    }
    Port port = deviceService.getPort(deviceId, portNumber);
    Optional<OchPort> ochPortOpt = OchPortHelper.asOchPort(port);

    if (ochPortOpt.isPresent()) {
        OchPort ochPort = ochPortOpt.get();
        GridType gridType = ochPort.lambda().gridType();
        ChannelSpacing channelSpacing = ochPort.lambda().channelSpacing();
        int slotGranularity = ochPort.lambda().slotGranularity();
        int multiplier = getMultiplier(wavelength, gridType, channelSpacing);
        return new OchSignal(gridType, channelSpacing, multiplier, slotGranularity);
    } else {
        return null;
    }

}
 
Example #18
Source File: OchPortHelper.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates OCh port DefaultPortDescription based on the supplied information.
 *
 * @param number      port number
 * @param isEnabled   port enabled state
 * @param signalType  ODU signal type
 * @param isTunable   tunable wavelength capability
 * @param lambda      OCh signal
 * @param annotationsIn key/value annotations map
 * @return OCh port DefaultPortDescription with OCh annotations
 */
public static PortDescription ochPortDescription(PortNumber number,
                                                 boolean isEnabled,
                                                 OduSignalType signalType,
                                                 boolean isTunable,
                                                 OchSignal lambda,
                                                 SparseAnnotations annotationsIn) {

    Builder builder = DefaultAnnotations.builder();
    builder.putAll(annotationsIn);

    builder.set(TUNABLE, String.valueOf(isTunable));
    builder.set(LAMBDA, OchSignalCodec.encode(lambda).toString());
    builder.set(SIGNAL_TYPE, signalType.toString());

    DefaultAnnotations annotations = builder.build();
    long portSpeed = signalType.bitRate();
    return DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled)
            .type(Port.Type.OCH).portSpeed(portSpeed).annotations(annotations)
            .build();
}
 
Example #19
Source File: OplinkSwitchProtection.java    From onos with Apache License 2.0 5 votes vote down vote up
private int getActivePort() {
    Port port = handler().get(DeviceService.class)
            .getPort(data().deviceId(), PortNumber.portNumber(PRIMARY_PORT));
    if (port != null) {
        if (port.annotations().value(OpticalAnnotations.INPUT_PORT_STATUS)
                .equals(OpticalAnnotations.STATUS_IN_SERVICE)) {
            return PRIMARY_PORT;
        }
    }
    return SECONDARY_PORT;
}
 
Example #20
Source File: OchPortMapper.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<OchPort> as(Port port) {
    if (port instanceof OchPort) {
        return Optional.of((OchPort) port);
    }
    return super.as(port);
}
 
Example #21
Source File: OmsPortMapper.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected Optional<OmsPort> mapPort(Port port) {
    if (port instanceof OmsPort) {
        return Optional.of((OmsPort) port);
    }
    return OmsPortHelper.asOmsPort(port);
}
 
Example #22
Source File: VirtualNetworkDeviceManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Port getPort(DeviceId deviceId, PortNumber portNumber) {
    checkNotNull(deviceId, DEVICE_NULL);

    Optional<VirtualPort> foundPort =
            manager.getVirtualPorts(this.networkId, deviceId)
            .stream()
            .filter(port -> port.number().equals(portNumber))
            .findFirst();
    if (foundPort.isPresent()) {
        return foundPort.get();
    }
    return null;
}
 
Example #23
Source File: DevicesWebResource.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
  * Gets ports of all infrastructure devices.
  * Returns port details of all infrastructure devices.
  *
  * @onos.rsModel DevicesGetPorts
  * @return 200 OK with a collection of ports for all devices
  */
@GET
@Path("ports")
@Produces(MediaType.APPLICATION_JSON)
public Response getDevicesPorts() {
    DeviceService service = get(DeviceService.class);
    List<Port> result = Lists.newArrayList();
    service.getDevices().forEach(device -> {
            Optional<List<Port>> list = Optional.ofNullable(service.getPorts(device.id()));
            list.ifPresent(ports -> result.addAll(ports));
    });
    return ok(encodeArray(Port.class, "ports", result)).build();
}
 
Example #24
Source File: DefaultOpenstackNode.java    From onos with Apache License 2.0 5 votes vote down vote up
private PortNumber tunnelPortNum(String tunnelType) {
    if (dataIp == null) {
        return null;
    }
    DeviceService deviceService = DefaultServiceDirectory.getService(DeviceService.class);
    Port port = deviceService.getPorts(intgBridge).stream()
            .filter(p -> p.isEnabled() &&
                    Objects.equals(p.annotations().value(PORT_NAME), tunnelType))
            .findAny().orElse(null);
    return port != null ? port.number() : null;
}
 
Example #25
Source File: OduCltPortMapper.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<OduCltPort> as(Port port) {
    if (port instanceof OduCltPort) {
        return Optional.of((OduCltPort) port);
    }
    return super.as(port);
}
 
Example #26
Source File: FlowRuleJuniperImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to find if an interface has an IP address.
 * It will check the annotations of the port.
 *
 * @param port the port
 * @return true if the IP address is present. Otherwise false.
 */
private boolean isIp(Port port) {
    final String ipv4 = port.annotations().value(JuniperUtils.AK_IP);
    if (StringUtils.isEmpty(ipv4)) {
        return false;
    }
    try {
        Ip4Address.valueOf(ipv4);
    } catch (IllegalArgumentException e) {
        return false;
    }
    return true;
}
 
Example #27
Source File: EvpnManager.java    From onos with Apache License 2.0 5 votes vote down vote up
private PortNumber getTunnlePort(DeviceId deviceId) {
    Iterable<Port> ports = deviceService.getPorts(deviceId);
    Collection<PortNumber> localTunnelPorts = getLocalTunnelPorts(ports);
    if (localTunnelPorts.isEmpty()) {
        log.error(CANNOT_FIND_TUNNEL_PORT_DEVICE, deviceId);
        return null;
    }
    return localTunnelPorts.iterator().next();
}
 
Example #28
Source File: VtnData.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Get local tunnel ports.
 *
 * @param ports Iterable of Port
 * @return Collection of PortNumber
 */
public static Collection<PortNumber> getLocalTunnelPorts(Iterable<Port> ports) {
    Collection<PortNumber> localTunnelPorts = new ArrayList<>();
    Sets.newHashSet(ports).stream()
            .filter(p -> !p.number().equals(PortNumber.LOCAL))
            .forEach(p -> {
                if (p.annotations().value(AnnotationKeys.PORT_NAME)
                        .startsWith(PORT_HEAD)) {
                    localTunnelPorts.add(p.number());
                }
            });
    return localTunnelPorts;
}
 
Example #29
Source File: GnmiDeviceStateSubscriber.java    From onos with Apache License 2.0 5 votes vote down vote up
private void subscribeIfNeeded(DeviceId deviceId) {

        Set<PortNumber> ports = deviceService.getPorts(deviceId).stream()
                .map(Port::number)
                .collect(Collectors.toSet());

        if (Objects.equals(ports, deviceSubscribed.get(deviceId))) {
            // Already subscribed for the same ports.
            return;
        }

        // Subscribe for the new set of ports.
        deviceSubscribed.put(deviceId, ports);

        // Send subscription request.
        final SubscriptionList subscriptionList = SubscriptionList.newBuilder()
                .setMode(SubscriptionList.Mode.STREAM)
                .setUpdatesOnly(true)
                .addAllSubscription(ports.stream().map(
                        port -> Subscription.newBuilder()
                                .setPath(interfaceOperStatusPath(port.name()))
                                .setMode(SubscriptionMode.ON_CHANGE)
                                .build()).collect(Collectors.toList()))
                .build();
        gnmiController.get(deviceId).subscribe(
                SubscribeRequest.newBuilder()
                        .setSubscribe(subscriptionList)
                        .build());

        log.info("Started gNMI subscription for {} ports on {}", ports.size(), deviceId);
    }
 
Example #30
Source File: DeviceEventTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
@Test
public void withTime() {
    Device device = createDevice();
    Port port = new DefaultPort(device, PortNumber.portNumber(123), true);
    DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED,
            device, port, 123L);
    validateEvent(event, DeviceEvent.Type.DEVICE_ADDED, device, 123L);
    assertEquals("incorrect port", port, event.port());
}