Search in sources :

Example 16 with DefaultPort

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

the class LinkDiscoveryCiscoImpl method findDestinationPortByName.

private Port findDestinationPortByName(String remotePortName, String remotePortDesc, DeviceService deviceService, Device remoteDevice) {
    Optional<Port> remotePort = deviceService.getPorts(remoteDevice.id()).stream().filter(port -> remotePortName.equals(port.annotations().value(PORT_NAME))).findAny();
    if (remotePort.isPresent()) {
        return remotePort.get();
    } else {
        Optional<Port> remotePortByDesc = deviceService.getPorts(remoteDevice.id()).stream().filter(port -> remotePortDesc.equals(port.annotations().value(PORT_NAME))).findAny();
        if (remotePortByDesc.isPresent()) {
            return remotePortByDesc.get();
        } else {
            int portNumber = Integer.valueOf(remotePortName.replaceAll("\\D+", ""));
            DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, remotePortName);
            return new DefaultPort(remoteDevice, PortNumber.portNumber(portNumber), true, annotations.build());
        }
    }
}
Also used : Tools(org.onlab.util.Tools) Supplier(com.google.common.base.Supplier) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) DefaultDevice(org.onosproject.net.DefaultDevice) AnnotationKeys(org.onosproject.net.AnnotationKeys) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) MediaType(javax.ws.rs.core.MediaType) Lists(com.google.common.collect.Lists) ByteArrayInputStream(java.io.ByteArrayInputStream) Port(org.onosproject.net.Port) JsonNode(com.fasterxml.jackson.databind.JsonNode) StreamSupport(java.util.stream.StreamSupport) LinkDescription(org.onosproject.net.link.LinkDescription) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DefaultPort(org.onosproject.net.DefaultPort) Device(org.onosproject.net.Device) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) ProviderId(org.onosproject.net.provider.ProviderId) IOException(java.io.IOException) RestSBController(org.onosproject.protocol.rest.RestSBController) Sets(com.google.common.collect.Sets) LinkDiscovery(org.onosproject.net.behaviour.LinkDiscovery) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) List(java.util.List) DriverHandler(org.onosproject.net.driver.DriverHandler) Stream(java.util.stream.Stream) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) ChassisId(org.onlab.packet.ChassisId) InputStream(java.io.InputStream) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultPort(org.onosproject.net.DefaultPort)

Example 17 with DefaultPort

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

the class PortCodec method decode.

/**
 * {@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);
}
Also used : Type(org.onosproject.net.Port.Type) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DefaultDevice(org.onosproject.net.DefaultDevice) PortNumber(org.onosproject.net.PortNumber) DefaultPort(org.onosproject.net.DefaultPort)

Example 18 with DefaultPort

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

the class OpenstackSwitchingHostProviderTest method testProcessPortAddedForMigration.

/**
 * Tests the process port added method for migration case.
 */
@Test
public void testProcessPortAddedForMigration() {
    org.onosproject.net.Port port = new DefaultPort(DEV1, P2, true, ANNOTATIONS);
    target.processPortAdded(port);
    HostId hostId = HostId.hostId(HOST_MAC);
    verifyHostLocationResult(hostId, HOST_LOC12);
}
Also used : HostId(org.onosproject.net.HostId) DefaultPort(org.onosproject.net.DefaultPort) Test(org.junit.Test)

Example 19 with DefaultPort

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

the class OpenstackSwitchingHostProviderTest method testProcessPortAddedForNewAddition.

/**
 * Tests the process port added method for new addition case.
 */
@Test
public void testProcessPortAddedForNewAddition() {
    org.onosproject.net.Port port = new DefaultPort(DEV2, P1, true, ANNOTATIONS);
    DeviceEvent event = new DeviceEvent(DeviceEvent.Type.PORT_ADDED, DEV2, port);
    target.portAddedHelper(event);
    HostId hostId = HostId.hostId(HOST_MAC2);
    HostDescription hostDesc = new DefaultHostDescription(HOST_MAC2, VlanId.NONE, new HostLocation(CP21, System.currentTimeMillis()), ImmutableSet.of(HOST_IP11), ANNOTATIONS);
    verifyHostResult(hostId, hostDesc);
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) HostLocation(org.onosproject.net.HostLocation) HostId(org.onosproject.net.HostId) DefaultPort(org.onosproject.net.DefaultPort) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) HostDescription(org.onosproject.net.host.HostDescription) Test(org.junit.Test)

Example 20 with DefaultPort

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

the class SimpleDeviceStore method composePort.

/**
 * Returns a Port, merging description given from multiple Providers.
 *
 * @param device   device the port is on
 * @param number   port number
 * @param descsMap Collection of Descriptions from multiple providers
 * @return Port instance
 */
private Port composePort(Device device, PortNumber number, Map<ProviderId, DeviceDescriptions> descsMap) {
    ProviderId primary = pickPrimaryPid(descsMap);
    DeviceDescriptions primDescs = descsMap.get(primary);
    // if no primary, assume not enabled
    // TODO: revisit this default port enabled/disabled behavior
    boolean isEnabled = false;
    DefaultAnnotations annotations = DefaultAnnotations.builder().build();
    final PortDescription portDesc = primDescs.getPortDesc(number);
    if (portDesc != null) {
        isEnabled = portDesc.isEnabled();
        annotations = merge(annotations, portDesc.annotations());
    }
    for (Entry<ProviderId, DeviceDescriptions> e : descsMap.entrySet()) {
        if (e.getKey().equals(primary)) {
            continue;
        }
        // TODO: should keep track of Description timestamp
        // and only merge conflicting keys when timestamp is newer
        // Currently assuming there will never be a key conflict between
        // providers
        // annotation merging. not so efficient, should revisit later
        final PortDescription otherPortDesc = e.getValue().getPortDesc(number);
        if (otherPortDesc != null) {
            annotations = merge(annotations, otherPortDesc.annotations());
        }
    }
    return portDesc == null ? new DefaultPort(device, number, false, annotations) : new DefaultPort(device, number, isEnabled, portDesc.type(), portDesc.portSpeed(), annotations);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) DefaultPort(org.onosproject.net.DefaultPort)

Aggregations

DefaultPort (org.onosproject.net.DefaultPort)33 Test (org.junit.Test)25 Port (org.onosproject.net.Port)21 Device (org.onosproject.net.Device)12 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)10 DefaultDevice (org.onosproject.net.DefaultDevice)8 DeviceEvent (org.onosproject.net.device.DeviceEvent)8 PortNumber (org.onosproject.net.PortNumber)7 Annotations (org.onosproject.net.Annotations)6 ConnectPoint (org.onosproject.net.ConnectPoint)5 DeviceId (org.onosproject.net.DeviceId)4 ProviderId (org.onosproject.net.provider.ProviderId)4 Iterator (java.util.Iterator)3 Frequency (org.onlab.util.Frequency)3 HostId (org.onosproject.net.HostId)3 PortDescription (org.onosproject.net.device.PortDescription)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 Supplier (com.google.common.base.Supplier)2 Sets (com.google.common.collect.Sets)2