Search in sources :

Example 6 with DefaultPort

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

the class KryoSerializerTest method testDefaultPort.

@Test
public void testDefaultPort() {
    testSerializedEquals(new DefaultPort(DEV1, P1, true));
    testSerializedEquals(new DefaultPort(DEV1, P1, true, A1_2));
}
Also used : DefaultPort(org.onosproject.net.DefaultPort) Test(org.junit.Test)

Example 7 with DefaultPort

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

the class ECDeviceStore method composePort.

/**
 * Returns a Port, merging descriptions from multiple Providers.
 *
 * @param device   device the port is on
 * @param number   port number
 * @return Port instance
 */
private Port composePort(Device device, PortNumber number) {
    Map<ProviderId, PortDescription> descriptions = Maps.newHashMap();
    portDescriptions.entrySet().forEach(entry -> {
        PortKey portKey = entry.getKey();
        if (portKey.deviceId().equals(device.id()) && portKey.portNumber().equals(number)) {
            descriptions.put(portKey.providerId(), entry.getValue());
        }
    });
    ProviderId primary = getPrimaryProviderId(device.id());
    PortDescription primaryDescription = descriptions.get(primary);
    // if no primary, assume not enabled
    boolean isEnabled = false;
    DefaultAnnotations annotations = DefaultAnnotations.builder().build();
    if (primaryDescription != null) {
        isEnabled = primaryDescription.isEnabled();
        annotations = merge(annotations, primaryDescription.annotations());
    }
    Port updated = null;
    for (Entry<ProviderId, PortDescription> e : descriptions.entrySet()) {
        if (e.getKey().equals(primary)) {
            continue;
        }
        annotations = merge(annotations, e.getValue().annotations());
        updated = buildTypedPort(device, number, isEnabled, e.getValue(), annotations);
    }
    if (primaryDescription == null) {
        return updated == null ? new DefaultPort(device, number, false, annotations) : updated;
    }
    return updated == null ? buildTypedPort(device, number, isEnabled, primaryDescription, annotations) : updated;
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) PortDescription(org.onosproject.net.device.PortDescription) DefaultPort(org.onosproject.net.DefaultPort)

Example 8 with DefaultPort

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

the class GossipDeviceStore 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
    boolean isEnabled = false;
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
    Timestamp newest = null;
    final Timestamped<PortDescription> portDesc = primDescs.getPortDesc(number);
    if (portDesc != null) {
        isEnabled = portDesc.value().isEnabled();
        annotations.putAll(portDesc.value().annotations());
        newest = portDesc.timestamp();
    }
    Port updated = null;
    for (Entry<ProviderId, DeviceDescriptions> e : descsMap.entrySet()) {
        if (e.getKey().equals(primary)) {
            continue;
        }
        // Note: should keep track of Description timestamp in the future
        // 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 Timestamped<PortDescription> otherPortDesc = e.getValue().getPortDesc(number);
        if (otherPortDesc != null) {
            if (newest != null && newest.isNewerThan(otherPortDesc.timestamp())) {
                continue;
            }
            annotations.putAll(otherPortDesc.value().annotations());
            PortDescription other = otherPortDesc.value();
            updated = buildTypedPort(device, number, isEnabled, other, annotations.build());
            newest = otherPortDesc.timestamp();
        }
    }
    if (portDesc == null) {
        return updated == null ? new DefaultPort(device, number, false, annotations.build()) : updated;
    }
    PortDescription current = portDesc.value();
    return updated == null ? buildTypedPort(device, number, isEnabled, current, annotations.build()) : updated;
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) PortDescription(org.onosproject.net.device.PortDescription) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp) DefaultPort(org.onosproject.net.DefaultPort)

Example 9 with DefaultPort

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

the class VirtualNetworkIntentManagerTest method setupVirtualNetworkTopology.

/**
 * 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;
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultPort(org.onosproject.net.DefaultPort)

Example 10 with DefaultPort

use of org.onosproject.net.DefaultPort 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)

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