Java Code Examples for org.onosproject.net.Port#number()

The following examples show how to use org.onosproject.net.Port#number() . 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: LinkDiscoveryCiscoImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
private static Set<LinkDescription> buildLinkPair(DeviceId localDevId,
                                                  Port localPort,
                                                  DeviceId remoteDevId,
                                                  Port remotePort) {

    Set<LinkDescription> linkDescriptions = Sets.newHashSet();
    ConnectPoint local = new ConnectPoint(localDevId, localPort.number());
    ConnectPoint remote = new ConnectPoint(remoteDevId, remotePort.number());
    DefaultAnnotations annotations = DefaultAnnotations.builder()
            .set("layer", "ETHERNET")
            .build();
    linkDescriptions.add(new DefaultLinkDescription(
            remote, local, Link.Type.DIRECT, true, annotations));

    return linkDescriptions;
}
 
Example 2
Source File: LinkDiscoveryAristaImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
private static Set<LinkDescription> buildLinkPair(DeviceId localDevId,
                                                  Port localPort,
                                                  DeviceId remoteDevId,
                                                  Port remotePort) {

    Set<LinkDescription> linkDescriptions = Sets.newHashSet();
    ConnectPoint local = new ConnectPoint(localDevId, localPort.number());
    ConnectPoint remote = new ConnectPoint(remoteDevId, remotePort.number());
    DefaultAnnotations annotations = DefaultAnnotations.builder()
            .set(AnnotationKeys.LAYER, "ETHERNET")
            .build();

    linkDescriptions.add(new DefaultLinkDescription(
            remote, local, Link.Type.DIRECT, true, annotations));

    return linkDescriptions;
}
 
Example 3
Source File: FlowStatisticManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Map<ConnectPoint, List<FlowEntryWithLoad>> loadAllByType(Device device,
                                                              FlowEntry.FlowLiveType liveType,
                                                              Instruction.Type instType) {
    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 = loadAllPortInternal(cp, liveType, instType);
        allLoad.put(cp, fel);
    }

    return allLoad;
}
 
Example 4
Source File: AddOpticalIntentCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
private ConnectPoint createConnectPoint(String devicePortString) {
    String[] splitted = devicePortString.split("/");

    checkArgument(splitted.length == 2,
            "Connect point must be in \"deviceUri/portNumber\" format");

    DeviceId deviceId = DeviceId.deviceId(splitted[0]);
    DeviceService deviceService = get(DeviceService.class);

    List<Port> ports = deviceService.getPorts(deviceId);

    for (Port port : ports) {
        if (splitted[1].equals(port.number().name())) {
            return new ConnectPoint(deviceId, port.number());
        }
    }

    return null;
}
 
Example 5
Source File: RoadmPortViewMessageHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void populateRow(TableModel.Row row, Port port, DeviceId deviceId) {
    PortNumber portNum = port.number();
    getFrequencyLimit(deviceId, portNum);
    row.cell(ID, portNum.toLong())
            .cell(REVERSE_PORT, RoadmUtil.getAnnotation(port.annotations(),
                    OpticalPathIntent.REVERSE_PORT_ANNOTATION_KEY))
            .cell(TYPE, port.type())
            .cell(ENABLED, port.isEnabled())
            .cell(NAME, RoadmUtil.getAnnotation(port.annotations(), AnnotationKeys.PORT_NAME))
            .cell(MIN_FREQ, RoadmUtil.asTHz(minFreq))
            .cell(MAX_FREQ, RoadmUtil.asTHz(maxFreq))
            .cell(GRID, RoadmUtil.asGHz(channelSpacing))
            .cell(CURR_FREQ, getWavelength(deviceId, portNum))
            .cell(POWER_RANGE, getPowerRange(deviceId, portNum))
            .cell(CURRENT_POWER, getCurrentPower(deviceId, portNum))
            .cell(CURRENT_INPUT_POWER, getCurrentInputPower(deviceId, portNum))
            .cell(SERVICE_STATE, getPortServiceState(deviceId, portNum))
            .cell(MODULATION, getModulation(deviceId, portNum))
            .cell(TARGET_POWER, getTargetPower(deviceId, portNum))
            .cell(HAS_TARGET_POWER, roadmService.hasPortTargetPower(deviceId, portNum))
            .cell(PRE_FEC_BER, getPreFecBer(deviceId, portNum))
            .cell(POST_FEC_BER, getPostFecBer(deviceId, portNum));
}
 
Example 6
Source File: OpenstackSwitchingHostProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Processes port removal event.
 * Once a port removal event is detected, it tries to look for a host
 * instance through host provider by giving connect point information,
 * and vanishes it.
 *
 * @param port ONOS port
 */
private void processPortRemoved(Port port) {
    ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number());

    Set<Host> hosts = hostService.getConnectedHosts(connectPoint);

    hosts.forEach(h -> {
        Optional<HostLocation> hostLocation = h.locations().stream()
                .filter(l -> l.deviceId().equals(port.element().id()))
                .filter(l -> l.port().equals(port.number())).findAny();

        // if the host contains only one filtered location, we remove the host
        if (h.locations().size() == 1) {
            hostProviderService.hostVanished(h.id());
        }

        // if the host contains multiple locations, we simply remove the
        // host location
        if (h.locations().size() > 1 && hostLocation.isPresent()) {
            hostProviderService.removeLocationFromHost(h.id(), hostLocation.get());
        }
    });
}
 
Example 7
Source File: TapiSipHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
public TapiSipHandler setPort(Port port) {
    if (!isSip(port)) {
        throw new IllegalStateException("Not allowed to use this port as SIP.");
    }
    ConnectPoint cp = new ConnectPoint(port.element().id(), port.number());
    String portType = port.annotations().value(PORT_TYPE);
    return setConnectPoint(cp, portType);
}
 
Example 8
Source File: DeviceViewMessageHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private ObjectNode portData(Port p, DeviceId id) {
    ObjectNode port = objectNode();
    LinkService ls = get(LinkService.class);
    String name = p.annotations().value(AnnotationKeys.PORT_NAME);

    port.put(ID, capitalizeFully(p.number().toString()));
    port.put(TYPE, capitalizeFully(p.type().toString()));
    port.put(SPEED, p.portSpeed());
    port.put(ENABLED, p.isEnabled());
    port.put(NAME, name != null ? name : "");

    ConnectPoint connectPoint = new ConnectPoint(id, p.number());
    Set<Link> links = ls.getEgressLinks(connectPoint);
    if (!links.isEmpty()) {
        StringBuilder egressLinks = new StringBuilder();
        for (Link l : links) {
            ConnectPoint dest = l.dst();
            egressLinks.append(dest.elementId()).append("/")
                    .append(dest.port()).append(" ");
        }
        port.put(LINK_DEST, egressLinks.toString());
    } else {
        HostService hs = get(HostService.class);
        Set<Host> hosts = hs.getConnectedHosts(connectPoint);
        if (hosts != null && !hosts.isEmpty()) {
            port.put(LINK_DEST, hosts.iterator().next().id().toString());
        }
    }

    return port;
}
 
Example 9
Source File: DefaultOpenstackNode.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public PortNumber patchPortNum() {
    if (type == NodeType.COMPUTE) {
        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), PATCH_INTG_BRIDGE))
            .findAny().orElse(null);
    return port != null ? port.number() : null;
}
 
Example 10
Source File: SegmentRoutingManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Adds or remove filtering rules for the given switchport. If switchport is
 * an edge facing port, additionally handles host probing and broadcast
 * rules. Must be called by local master of device.
 *
 * @param deviceId the device identifier
 * @param port the port to update
 */
void processPortUpdated(DeviceId deviceId, Port port) {
    // first we handle filtering rules associated with the port
    if (port.isEnabled()) {
        log.info("Switchport {}/{} enabled..programming filters",
                 deviceId, port.number());
        routingRulePopulator.processSinglePortFilters(deviceId, port.number(), true);
    } else {
        log.info("Switchport {}/{} disabled..removing filters",
                 deviceId, port.number());
        routingRulePopulator.processSinglePortFilters(deviceId, port.number(), false);
    }

    // portUpdated calls are for ports that have gone down or up. For switch
    // to switch ports, link-events should take care of any re-routing or
    // group editing necessary for port up/down. Here we only process edge ports
    // that are already configured.
    ConnectPoint cp = new ConnectPoint(deviceId, port.number());
    VlanId untaggedVlan = interfaceService.getUntaggedVlanId(cp);
    VlanId nativeVlan = interfaceService.getNativeVlanId(cp);
    Set<VlanId> taggedVlans = interfaceService.getTaggedVlanId(cp);

    if (untaggedVlan == null && nativeVlan == null && taggedVlans.isEmpty()) {
        log.debug("Not handling port updated event for non-edge port (unconfigured) "
                + "dev/port: {}/{}", deviceId, port.number());
        return;
    }
    if (untaggedVlan != null) {
        processEdgePort(deviceId, port, untaggedVlan, true);
    }
    if (nativeVlan != null) {
        processEdgePort(deviceId, port, nativeVlan, true);
    }
    if (!taggedVlans.isEmpty()) {
        taggedVlans.forEach(tag -> processEdgePort(deviceId, port, tag, false));
    }
}
 
Example 11
Source File: McastHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private void processPortUpdateInternal(Device affectedDevice, Port affectedPort) {
    // Clean the filtering obj store. Edge port case.
    lastMcastChange.set(Instant.now());
    ConnectPoint portDown = new ConnectPoint(affectedDevice.id(), affectedPort.number());
    if (!affectedPort.isEnabled()) {
        log.info("Processing port down {}", portDown);
        updateFilterObjStoreByPort(portDown);
    }
}
 
Example 12
Source File: SelectGroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns port number of vxlan tunnel.
 *
 * @param deviceId target Device Id
 * @return portNumber
 */
private PortNumber getTunnelPort(DeviceId deviceId) {
    Port port = deviceService.getPorts(deviceId).stream()
            .filter(p -> p.annotations().value(PORT_NAME).equals(PORTNAME_PREFIX_TUNNEL))
            .findAny().orElse(null);

    if (port == null) {
        log.error("No TunnelPort was created.");
        return null;
    }
    return port.number();

}
 
Example 13
Source File: SfcFlowRuleInstallerImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
private PortNumber getVxlanPortNumber(DeviceId deviceId) {
    Iterable<Port> ports = deviceService.getPorts(deviceId);
    Port vxlanPort = Sets.newHashSet(ports).stream()
            .filter(p -> !p.number().equals(PortNumber.LOCAL))
            .filter(p -> p.annotations().value(AnnotationKeys.PORT_NAME)
                    .startsWith(VXLANPORT_HEAD))
            .findFirst().get();
    return vxlanPort.number();
}
 
Example 14
Source File: OpenstackVtapManager.java    From onos with Apache License 2.0 5 votes vote down vote up
private PortNumber portNumber(DeviceId deviceId, String interfaceName) {
    Port port = deviceService.getPorts(deviceId).stream()
            .filter(p -> p.isEnabled() &&
                    Objects.equals(p.annotations().value(PORT_NAME), interfaceName))
            .findAny().orElse(null);
    return port != null ? port.number() : null;
}
 
Example 15
Source File: DefaultOpenstackNode.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public PortNumber vlanPortNum() {
    if (vlanIntf == 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), vlanIntf))
            .findAny().orElse(null);
    return port != null ? port.number() : null;
}
 
Example 16
Source File: JuniperUtils.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Create one way LinkDescriptions.
 *
 * @param localDevId  the identity of the local device
 * @param localPort   the port of the local device
 * @param remoteDevId the identity of the remote device
 * @param remotePort  the port of the remote device
 * @param descs       the collection to which the link descriptions
 *                    should be added
 */
public static void createOneWayLinkDescription(DeviceId localDevId,
                                               Port localPort,
                                               DeviceId remoteDevId,
                                               Port remotePort,
                                               Set<LinkDescription> descs) {

    ConnectPoint local = new ConnectPoint(localDevId, localPort.number());
    ConnectPoint remote = new ConnectPoint(remoteDevId, remotePort.number());
    DefaultAnnotations annotations = DefaultAnnotations.builder()
            .set(AnnotationKeys.LAYER, "ETHERNET")
            .build();
    descs.add(new DefaultLinkDescription(
            remote, local, Link.Type.DIRECT, true, annotations));
}
 
Example 17
Source File: VirtualNetworkIntentManagerTest.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Method to create the virtual network for further testing.
 *
 * @return virtual network
 */
private VirtualNetwork setupVirtualNetworkTopology() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    VirtualDevice virtualDevice1 =
            manager.createVirtualDevice(virtualNetwork.id(), DID1);
    VirtualDevice virtualDevice2 =
            manager.createVirtualDevice(virtualNetwork.id(), DID2);
    VirtualDevice virtualDevice3 =
            manager.createVirtualDevice(virtualNetwork.id(), DID3);
    VirtualDevice virtualDevice4 =
            manager.createVirtualDevice(virtualNetwork.id(), DID4);

    Port port1 = new DefaultPort(virtualDevice1, PortNumber.portNumber(1), true);
    cp1 = new ConnectPoint(virtualDevice1.id(), port1.number());
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice1.id(), port1.number(), cp1);

    Port port2 = new DefaultPort(virtualDevice1, PortNumber.portNumber(2), true);
    cp2 = new ConnectPoint(virtualDevice1.id(), port2.number());
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice1.id(), port2.number(), cp2);

    Port port3 = new DefaultPort(virtualDevice2, PortNumber.portNumber(3), true);
    cp3 = new ConnectPoint(virtualDevice2.id(), port3.number());
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice2.id(), port3.number(), cp3);

    Port port4 = new DefaultPort(virtualDevice2, PortNumber.portNumber(4), true);
    cp4 = new ConnectPoint(virtualDevice2.id(), port4.number());
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice2.id(), port4.number(), cp4);

    Port port5 = new DefaultPort(virtualDevice3, PortNumber.portNumber(5), true);
    cp5 = new ConnectPoint(virtualDevice3.id(), port5.number());
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice3.id(), port5.number(), cp5);

    Port port6 = new DefaultPort(virtualDevice3, PortNumber.portNumber(6), true);
    cp6 = new ConnectPoint(virtualDevice3.id(), port6.number());
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice3.id(), port6.number(), cp6);

    link1 = manager.createVirtualLink(virtualNetwork.id(), cp1, cp3);
    virtualNetworkManagerStore.updateLink(link1, link1.tunnelId(), Link.State.ACTIVE);
    link2 = manager.createVirtualLink(virtualNetwork.id(), cp3, cp1);
    virtualNetworkManagerStore.updateLink(link2, link2.tunnelId(), Link.State.ACTIVE);
    link3 = manager.createVirtualLink(virtualNetwork.id(), cp4, cp5);
    virtualNetworkManagerStore.updateLink(link3, link3.tunnelId(), Link.State.ACTIVE);
    link4 = manager.createVirtualLink(virtualNetwork.id(), cp5, cp4);
    virtualNetworkManagerStore.updateLink(link4, link4.tunnelId(), Link.State.ACTIVE);

    vnetIntentService = new VirtualNetworkIntentManager(manager, virtualNetwork.id());
    vnetIntentService.intentStore = intentStore;
    return virtualNetwork;
}
 
Example 18
Source File: OpenstackSwitchingHostProvider.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Processes port addition event.
 * Once a port addition event is detected, it tries to create a host instance
 * with openstack augmented host information such as networkId, portId,
 * createTime, segmentId and notifies to host provider.
 *
 * @param port port object used in ONOS
 */
void processPortAdded(Port port) {
    // TODO check the node state is COMPLETE
    org.openstack4j.model.network.Port osPort = osNetworkService.port(port);
    if (osPort == null) {
        log.warn(ERR_ADD_HOST + "OpenStack port for {} not found", port);
        return;
    }

    Network osNet = osNetworkService.network(osPort.getNetworkId());
    if (osNet == null) {
        log.warn(ERR_ADD_HOST + "OpenStack network {} not found",
                osPort.getNetworkId());
        return;
    }

    if (osPort.getFixedIps().isEmpty()) {
        log.warn(ERR_ADD_HOST + "no fixed IP for port {}", osPort.getId());
        return;
    }

    MacAddress mac = MacAddress.valueOf(osPort.getMacAddress());
    HostId hostId = HostId.hostId(mac);

    /* typically one openstack port should only be bound to one fix IP address;
       however, openstack4j binds multiple fixed IPs to one port, this might
       be a defect of openstack4j implementation */

    // TODO: we need to find a way to bind multiple ports from multiple
    // openstack networks into one host sooner or later
    Set<IpAddress> fixedIps = osPort.getFixedIps().stream()
            .map(ip -> IpAddress.valueOf(ip.getIpAddress()))
            .collect(Collectors.toSet());

    // connect point is the combination of switch ID with port number where
    // the host is attached to
    ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number());

    long createTime = System.currentTimeMillis();

    // we check whether the host already attached to same locations
    Host host = hostService.getHost(hostId);

    // build host annotations to include a set of meta info from neutron
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder()
            .set(ANNOTATION_NETWORK_ID, osPort.getNetworkId())
            .set(ANNOTATION_PORT_ID, osPort.getId())
            .set(ANNOTATION_CREATE_TIME, String.valueOf(createTime));

    // FLAT typed network does not require segment ID
    Type netType = osNetworkService.networkType(osNet.getId());
    if (netType != FLAT) {
        annotations.set(ANNOTATION_SEGMENT_ID, osNet.getProviderSegID());
    }

    // build host description object
    HostDescription hostDesc = new DefaultHostDescription(
            mac,
            VlanId.NONE,
            new HostLocation(connectPoint, createTime),
            fixedIps,
            annotations.build());

    if (host != null) {
        Set<HostLocation> locations = host.locations().stream()
                .filter(l -> l.deviceId().equals(connectPoint.deviceId()))
                .filter(l -> l.port().equals(connectPoint.port()))
                .collect(Collectors.toSet());

        // newly added location is not in the existing location list,
        // therefore, we simply add this into the location list
        if (locations.isEmpty()) {
            hostProviderService.addLocationToHost(hostId,
                    new HostLocation(connectPoint, createTime));
        }

        // newly added location is in the existing location list,
        // the hostDetected method invocation in turn triggers host Update event
        if (locations.size() == 1) {
            hostProviderService.hostDetected(hostId, hostDesc, false);
        }
    } else {
        hostProviderService.hostDetected(hostId, hostDesc, false);
    }
}
 
Example 19
Source File: DefaultK8sNode.java    From onos with Apache License 2.0 4 votes vote down vote up
private PortNumber portNumber(DeviceId deviceId, String portName) {
    Port port = port(deviceId, portName);
    return port != null ? port.number() : null;
}
 
Example 20
Source File: K8sSwitchingHostProvider.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Processes port addition event.
 *
 * @param port port object used in ONOS
 */
private void processPortAdded(Port port) {
    K8sPort k8sPort = portToK8sPort(port);
    if (k8sPort == null) {
        log.warn(ERR_ADD_HOST + "Kubernetes port for {} not found", port);
        return;
    }

    K8sNetwork k8sNet = k8sNetworkService.network(k8sPort.networkId());
    if (k8sNet == null) {
        log.warn(ERR_ADD_HOST + "Kubernetes network {} not found",
                k8sPort.networkId());
        return;
    }

    MacAddress mac = k8sPort.macAddress();
    HostId hostId = HostId.hostId(mac);

    // connect point is the combination of switch ID with port number where
    // the host is attached to
    ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number());

    long createTime = System.currentTimeMillis();

    // update k8s port number by referring to ONOS port number

    k8sNetworkService.updatePort(k8sPort.updatePortNumber(port.number())
                                        .updateState(K8sPort.State.ACTIVE));

    // we check whether the host already attached to same locations
    Host host = hostService.getHost(hostId);

    // build host annotations to include a set of meta info from neutron
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder()
            .set(ANNOTATION_NETWORK_ID, k8sPort.networkId())
            .set(ANNOTATION_PORT_ID, k8sPort.portId())
            .set(ANNOTATION_CREATE_TIME, String.valueOf(createTime))
            .set(ANNOTATION_SEGMENT_ID, k8sNet.segmentId());

    HostDescription hostDesc = new DefaultHostDescription(
            mac,
            VlanId.NONE,
            new HostLocation(connectPoint, createTime),
            ImmutableSet.of(k8sPort.ipAddress()),
            annotations.build());

    if (host != null) {
        Set<HostLocation> locations = host.locations().stream()
                .filter(l -> l.deviceId().equals(connectPoint.deviceId()))
                .filter(l -> l.port().equals(connectPoint.port()))
                .collect(Collectors.toSet());

        // newly added location is not in the existing location list,
        // therefore, we simply add this into the location list
        if (locations.isEmpty()) {
            hostProviderService.addLocationToHost(hostId,
                    new HostLocation(connectPoint, createTime));
        }

        // newly added location is in the existing location list,
        // the hostDetected method invocation in turn triggers host Update event
        if (locations.size() == 1) {
            hostProviderService.hostDetected(hostId, hostDesc, false);
        }
    } else {
        hostProviderService.hostDetected(hostId, hostDesc, false);
    }
}