Search in sources :

Example 46 with Port

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

the class OmsPortHelperTest method testOmsPortDescriptionCanBeConvertedToOmsPort.

@Test
public void testOmsPortDescriptionCanBeConvertedToOmsPort() {
    PortNumber pn = PortNumber.portNumber(4900);
    boolean isEnabled = true;
    String anKey = "Base";
    String anValue = "value";
    SparseAnnotations an = DefaultAnnotations.builder().set(anKey, anValue).build();
    Frequency minF = Frequency.ofGHz(3);
    Frequency maxF = Frequency.ofGHz(33);
    Frequency grid = Frequency.ofGHz(2);
    PortDescription portDescription = OmsPortHelper.omsPortDescription(pn, isEnabled, minF, maxF, grid, an);
    Port port = new DefaultPort(DEV, portDescription.portNumber(), portDescription.isEnabled(), portDescription.type(), portDescription.portSpeed(), portDescription.annotations());
    Optional<OmsPort> maybeOms = OmsPortHelper.asOmsPort(port);
    assertTrue(maybeOms.isPresent());
    OmsPort oms = maybeOms.get();
    assertThat(oms.isEnabled(), is(isEnabled));
    assertThat(oms.number(), is(pn));
    assertThat(oms.annotations().value(anKey), is(anValue));
    assertThat("type is always OMS", oms.type(), is(Port.Type.OMS));
    assertThat("port speed is undefined", oms.portSpeed(), is(equalTo(0L)));
    assertThat(oms.maxFrequency(), is(maxF));
    assertThat(oms.minFrequency(), is(minF));
    assertThat(oms.grid(), is(grid));
    assertThat("((33-3)/2)+1 = 16", oms.totalChannels(), is((short) 16));
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) OmsPort(org.onosproject.net.optical.OmsPort) DefaultPort(org.onosproject.net.DefaultPort) OmsPort(org.onosproject.net.optical.OmsPort) Port(org.onosproject.net.Port) Frequency(org.onlab.util.Frequency) PortDescription(org.onosproject.net.device.PortDescription) PortNumber(org.onosproject.net.PortNumber) DefaultPort(org.onosproject.net.DefaultPort) Test(org.junit.Test)

Example 47 with Port

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

the class K8sSwitchingHostProvider method processPortAdded.

/**
 * Processes port addition event.
 *
 * @param port port object used in ONOS
 */
private void processPortAdded(Port port) {
    K8sPort k8sPort = portToK8sPortByName(port);
    if (k8sPort == null) {
        k8sPort = portToK8sPortByMac(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());
        // therefore, we simply add this into the location list
        if (locations.isEmpty()) {
            hostProviderService.addLocationToHost(hostId, new HostLocation(connectPoint, createTime));
        }
        // 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);
    }
}
Also used : HostLocation(org.onosproject.net.HostLocation) K8sNetworkingUtil.existingContainerPortByName(org.onosproject.k8snetworking.util.K8sNetworkingUtil.existingContainerPortByName) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) K8sNodeListener(org.onosproject.k8snode.api.K8sNodeListener) K8sNetworkListener(org.onosproject.k8snetworking.api.K8sNetworkListener) ConnectPoint(org.onosproject.net.ConnectPoint) HostProviderService(org.onosproject.net.host.HostProviderService) Port(org.onosproject.net.Port) PORT_MAC(org.onosproject.net.AnnotationKeys.PORT_MAC) K8sNetworkingUtil.isContainer(org.onosproject.k8snetworking.util.K8sNetworkingUtil.isContainer) MastershipService(org.onosproject.mastership.MastershipService) ANNOTATION_CREATE_TIME(org.onosproject.k8snetworking.api.Constants.ANNOTATION_CREATE_TIME) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) GENEVE(org.onosproject.k8snetworking.api.Constants.GENEVE) DeviceEvent(org.onosproject.net.device.DeviceEvent) K8sNetworkAdminService(org.onosproject.k8snetworking.api.K8sNetworkAdminService) DeviceId(org.onosproject.net.DeviceId) HostDescription(org.onosproject.net.host.HostDescription) INIT(org.onosproject.k8snode.api.K8sNodeState.INIT) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) GRE(org.onosproject.k8snetworking.api.Constants.GRE) HostService(org.onosproject.net.host.HostService) Strings(com.google.common.base.Strings) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) Component(org.osgi.service.component.annotations.Component) ANNOTATION_PORT_ID(org.onosproject.k8snetworking.api.Constants.ANNOTATION_PORT_ID) ANNOTATION_NETWORK_ID(org.onosproject.k8snetworking.api.Constants.ANNOTATION_NETWORK_ID) K8sNetworkEvent(org.onosproject.k8snetworking.api.K8sNetworkEvent) K8sPort(org.onosproject.k8snetworking.api.K8sPort) K8sNodeEvent(org.onosproject.k8snode.api.K8sNodeEvent) Activate(org.osgi.service.component.annotations.Activate) K8sNode(org.onosproject.k8snode.api.K8sNode) HostId(org.onosproject.net.HostId) ExecutorService(java.util.concurrent.ExecutorService) K8S_NETWORKING_APP_ID(org.onosproject.k8snetworking.api.Constants.K8S_NETWORKING_APP_ID) AbstractProvider(org.onosproject.net.provider.AbstractProvider) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) HostProvider(org.onosproject.net.host.HostProvider) VXLAN(org.onosproject.k8snetworking.api.Constants.VXLAN) VlanId(org.onlab.packet.VlanId) K8sHostService(org.onosproject.k8snode.api.K8sHostService) ProviderId(org.onosproject.net.provider.ProviderId) ANNOTATION_SEGMENT_ID(org.onosproject.k8snetworking.api.Constants.ANNOTATION_SEGMENT_ID) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) K8sNetworkingUtil.existingContainerPortByMac(org.onosproject.k8snetworking.util.K8sNetworkingUtil.existingContainerPortByMac) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) K8sNetworkingUtil.allK8sDevices(org.onosproject.k8snetworking.util.K8sNetworkingUtil.allK8sDevices) MacAddress(org.onlab.packet.MacAddress) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) Reference(org.osgi.service.component.annotations.Reference) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Host(org.onosproject.net.Host) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) ConnectPoint(org.onosproject.net.ConnectPoint) HostDescription(org.onosproject.net.host.HostDescription) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) HostLocation(org.onosproject.net.HostLocation) K8sPort(org.onosproject.k8snetworking.api.K8sPort)

Example 48 with Port

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

the class DefaultK8sNode method routerToExtPortNum.

@Override
public PortNumber routerToExtPortNum() {
    if (mode() == PASSTHROUGH) {
        K8sHostService hostService = DefaultServiceDirectory.getService(K8sHostService.class);
        Port port = null;
        for (K8sHost host : hostService.hosts()) {
            if (host.nodeNames().contains(hostname())) {
                for (K8sRouterBridge bridge : host.routerBridges()) {
                    if (bridge.segmentId() == segmentId()) {
                        port = port(bridge.deviceId(), routerToExtPatchPortName());
                    }
                }
            }
        }
        if (port == null) {
            return null;
        } else {
            return port.number();
        }
    }
    return null;
}
Also used : Port(org.onosproject.net.Port)

Example 49 with Port

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

the class DefaultK8sNode method routerPortNum.

@Override
public PortNumber routerPortNum() {
    if (mode() == PASSTHROUGH) {
        K8sHostService hostService = DefaultServiceDirectory.getService(K8sHostService.class);
        Port port = null;
        for (K8sHost host : hostService.hosts()) {
            if (host.nodeNames().contains(hostname())) {
                for (K8sRouterBridge bridge : host.routerBridges()) {
                    if (bridge.segmentId() == segmentId()) {
                        port = port(bridge.deviceId(), routerPortName());
                    }
                }
            }
        }
        if (port == null) {
            return null;
        } else {
            return port.number();
        }
    }
    return null;
}
Also used : Port(org.onosproject.net.Port)

Example 50 with Port

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

the class DefaultK8sNode method macAddress.

private MacAddress macAddress(DeviceId deviceId, String portName) {
    Port port = port(deviceId, portName);
    Annotations annots = port.annotations();
    return annots != null ? MacAddress.valueOf(annots.value(PORT_MAC)) : null;
}
Also used : Annotations(org.onosproject.net.Annotations) Port(org.onosproject.net.Port)

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