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));
}
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());
}
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;
}
}
}
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();
}
}
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();
}
Aggregations