Search in sources :

Example 1 with OmsPort

use of org.onosproject.net.optical.OmsPort 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 2 with OmsPort

use of org.onosproject.net.optical.OmsPort in project onos by opennetworkinglab.

the class OFOpticalSwitch13LambdaQuery method queryLambdas.

@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());
}
Also used : IntStream(java.util.stream.IntStream) LambdaQuery(org.onosproject.net.behaviour.LambdaQuery) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Set(java.util.Set) GuavaCollectors(org.onlab.util.GuavaCollectors) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) OchSignal(org.onosproject.net.OchSignal) OmsPort(org.onosproject.net.optical.OmsPort) OpticalDeviceServiceView.opticalView(org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView) Port(org.onosproject.net.Port) ChannelSpacing(org.onosproject.net.ChannelSpacing) Collections(java.util.Collections) OmsPort(org.onosproject.net.optical.OmsPort) OmsPort(org.onosproject.net.optical.OmsPort) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService)

Example 3 with OmsPort

use of org.onosproject.net.optical.OmsPort in project onos by opennetworkinglab.

the class OpticalPortsListCommand method printPorts.

@Override
protected void printPorts(DeviceService service, Device device) {
    List<Port> ports = new ArrayList<>(service.getPorts(device.id()));
    ports.sort((p1, p2) -> Long.signum(p1.number().toLong() - p2.number().toLong()));
    for (Port port : ports) {
        if (!isIncluded(port)) {
            continue;
        }
        String portName = port.number().toString();
        String portIsEnabled = port.isEnabled() ? "enabled" : "disabled";
        String portType = port.type().toString().toLowerCase();
        switch(port.type()) {
            case OCH:
                if (port instanceof OchPort) {
                    OchPort och = (OchPort) port;
                    print(FMT_OCH, portName, portIsEnabled, portType, och.signalType().toString(), och.isTunable() ? "yes" : "no", annotations(och.unhandledAnnotations()));
                    break;
                }
                print("WARN: OchPort but not on OpticalDevice or ill-formed");
                print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations()));
                break;
            case ODUCLT:
                if (port instanceof OduCltPort) {
                    OduCltPort oduCltPort = (OduCltPort) port;
                    print(FMT_ODUCLT_OTU, portName, portIsEnabled, portType, oduCltPort.signalType().toString(), annotations(oduCltPort.unhandledAnnotations()));
                    break;
                }
                print("WARN: OduCltPort but not on OpticalDevice or ill-formed");
                print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations()));
                break;
            case OMS:
                if (port instanceof OmsPort) {
                    OmsPort oms = (OmsPort) port;
                    print(FMT_OMS, portName, portIsEnabled, portType, oms.minFrequency().asHz() / Frequency.ofGHz(1).asHz(), oms.maxFrequency().asHz() / Frequency.ofGHz(1).asHz(), oms.grid().asHz() / Frequency.ofGHz(1).asHz(), oms.totalChannels(), annotations(oms.unhandledAnnotations()));
                    break;
                }
                print("WARN: OmsPort but not on OpticalDevice or ill-formed");
                print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations()));
                break;
            case OTU:
                if (port instanceof OtuPort) {
                    OtuPort otuPort = (OtuPort) port;
                    print(FMT_ODUCLT_OTU, portName, portIsEnabled, portType, otuPort.signalType().toString(), annotations(otuPort.unhandledAnnotations()));
                    break;
                }
                print("WARN: OtuPort but not on OpticalDevice or ill-formed");
                print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations()));
                break;
            default:
                // do not print non-optical ports
                break;
        }
    }
}
Also used : OmsPort(org.onosproject.net.optical.OmsPort) OtuPort(org.onosproject.net.optical.OtuPort) OtuPort(org.onosproject.net.optical.OtuPort) OmsPort(org.onosproject.net.optical.OmsPort) OduCltPort(org.onosproject.net.optical.OduCltPort) Port(org.onosproject.net.Port) OchPort(org.onosproject.net.optical.OchPort) ArrayList(java.util.ArrayList) OduCltPort(org.onosproject.net.optical.OduCltPort) OchPort(org.onosproject.net.optical.OchPort)

Example 4 with OmsPort

use of org.onosproject.net.optical.OmsPort in project onos by opennetworkinglab.

the class OmsPortHelper method asOmsPort.

public static Optional<OmsPort> asOmsPort(Port port) {
    if (port instanceof OmsPort) {
        return Optional.of((OmsPort) port);
    }
    try {
        Annotations an = port.annotations();
        Frequency minFrequency = Frequency.ofHz(Long.parseLong(an.value(OpticalAnnotations.MIN_FREQ_HZ)));
        Frequency maxFrequency = Frequency.ofHz(Long.parseLong(an.value(OpticalAnnotations.MAX_FREQ_HZ)));
        Frequency grid = Frequency.ofHz(Long.parseLong(an.value(OpticalAnnotations.GRID_HZ)));
        return Optional.of(new DefaultOmsPort(port, minFrequency, maxFrequency, grid));
    } catch (NumberFormatException e) {
        log.warn("{} was not well-formed OMS port.", port, e);
        return Optional.empty();
    }
}
Also used : DefaultOmsPort(org.onosproject.net.optical.impl.DefaultOmsPort) OmsPort(org.onosproject.net.optical.OmsPort) OpticalAnnotations(org.onosproject.net.optical.OpticalAnnotations) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) SparseAnnotations(org.onosproject.net.SparseAnnotations) Frequency(org.onlab.util.Frequency) DefaultOmsPort(org.onosproject.net.optical.impl.DefaultOmsPort)

Example 5 with OmsPort

use of org.onosproject.net.optical.OmsPort in project onos by opennetworkinglab.

the class DefaultOmsPortTest method testEquality.

@Test
public void testEquality() {
    PortNumber pn = PortNumber.portNumber(4900);
    Annotations an = DefaultAnnotations.builder().set("Base", "value").build();
    Annotations an2 = DefaultAnnotations.builder().set("Base", "value2").build();
    Port base = new DefaultPort(DEV, pn, true, Port.Type.VIRTUAL, 2, an);
    Frequency minF = Frequency.ofGHz(3);
    Frequency maxF = Frequency.ofGHz(33);
    Frequency grid = Frequency.ofGHz(2);
    // reference OMS port
    OmsPort oms = new DefaultOmsPort(base, minF, maxF, grid);
    new EqualsTester().addEqualityGroup(oms, // different base port type or portspeed is ignored
    new DefaultOmsPort(new DefaultPort(DEV, pn, true, an), minF, maxF, grid)).addEqualityGroup(new DefaultOmsPort(new DefaultPort(DEV, portNumber(1), true, an), minF, maxF, grid)).addEqualityGroup(new DefaultOmsPort(new DefaultPort(DEV, pn, false, an), minF, maxF, grid)).addEqualityGroup(new DefaultOmsPort(new DefaultPort(DEV, pn, true, an2), minF, maxF, grid)).addEqualityGroup(new DefaultOmsPort(base, Frequency.ofKHz(3), maxF, grid)).addEqualityGroup(new DefaultOmsPort(base, minF, Frequency.ofKHz(33), grid)).addEqualityGroup(new DefaultOmsPort(base, minF, maxF, Frequency.ofKHz(2))).testEquals();
}
Also used : OmsPort(org.onosproject.net.optical.OmsPort) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) EqualsTester(com.google.common.testing.EqualsTester) DefaultPort(org.onosproject.net.DefaultPort) OmsPort(org.onosproject.net.optical.OmsPort) Port(org.onosproject.net.Port) Frequency(org.onlab.util.Frequency) PortNumber(org.onosproject.net.PortNumber) DefaultPort(org.onosproject.net.DefaultPort) Test(org.junit.Test)

Aggregations

OmsPort (org.onosproject.net.optical.OmsPort)6 Port (org.onosproject.net.Port)5 Frequency (org.onlab.util.Frequency)4 PortNumber (org.onosproject.net.PortNumber)4 Test (org.junit.Test)3 Annotations (org.onosproject.net.Annotations)3 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)3 DefaultPort (org.onosproject.net.DefaultPort)3 SparseAnnotations (org.onosproject.net.SparseAnnotations)2 EqualsTester (com.google.common.testing.EqualsTester)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Set (java.util.Set)1 IntStream (java.util.stream.IntStream)1 GuavaCollectors (org.onlab.util.GuavaCollectors)1 ChannelSpacing (org.onosproject.net.ChannelSpacing)1 OchSignal (org.onosproject.net.OchSignal)1 LambdaQuery (org.onosproject.net.behaviour.LambdaQuery)1 DeviceService (org.onosproject.net.device.DeviceService)1 PortDescription (org.onosproject.net.device.PortDescription)1