use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class PortWaveLengthCommand method createOchSignalFromWavelength.
private OchSignal createOchSignalFromWavelength(DeviceService deviceService, ConnectPoint cp) {
long wavelength = Long.parseLong(parameter);
if (wavelength == 0L) {
return null;
}
Port port = deviceService.getPort(cp);
Optional<OchPort> ochPortOpt = OchPortHelper.asOchPort(port);
if (ochPortOpt.isPresent()) {
OchPort ochPort = ochPortOpt.get();
GridType gridType = ochPort.lambda().gridType();
ChannelSpacing channelSpacing = ochPort.lambda().channelSpacing();
int slotGranularity = ochPort.lambda().slotGranularity();
int multiplier = getMultplier(wavelength, gridType, channelSpacing);
return new OchSignal(gridType, channelSpacing, multiplier, slotGranularity);
} else {
print("[ERROR] connect point %s is not OChPort", cp);
return null;
}
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class LinkDiscoveryAristaImpl method findRemoteDeviceByChassisId.
private Optional<Device> findRemoteDeviceByChassisId(DeviceService deviceService, String remoteChassisIdString) {
String forMacTmp = remoteChassisIdString.replace(".", "").replaceAll("(.{2})", "$1:").trim().substring(0, 17);
MacAddress mac = MacAddress.valueOf(forMacTmp);
Supplier<Stream<Device>> deviceStream = () -> StreamSupport.stream(deviceService.getAvailableDevices().spliterator(), false);
Optional<Device> remoteDeviceOptional = deviceStream.get().filter(device -> device.chassisId() != null && MacAddress.valueOf(device.chassisId().value()).equals(mac)).findAny();
if (remoteDeviceOptional.isPresent()) {
log.debug("remoteDevice found by chassis id: {}", forMacTmp);
return remoteDeviceOptional;
} else {
remoteDeviceOptional = deviceStream.get().filter(device -> Tools.stream(deviceService.getPorts(device.id())).anyMatch(port -> port.annotations().keys().contains(AnnotationKeys.PORT_MAC) && MacAddress.valueOf(port.annotations().value(AnnotationKeys.PORT_MAC)).equals(mac))).findAny();
if (remoteDeviceOptional.isPresent()) {
log.debug("remoteDevice found by port mac: {}", forMacTmp);
return remoteDeviceOptional;
} else {
return Optional.empty();
}
}
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class LinkDiscoveryAristaImpl method findDestinationPortByName.
private Optional<Port> findDestinationPortByName(String remotePortName, DeviceService deviceService, Device remoteDevice) {
Optional<Port> remotePort = deviceService.getPorts(remoteDevice.id()).stream().filter(port -> remotePortName.equals(port.annotations().value(AnnotationKeys.PORT_NAME))).findAny();
if (remotePort.isPresent()) {
return remotePort;
} else {
int portNumber = Integer.valueOf(remotePortName.replaceAll("\\D+", ""));
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, remotePortName);
return Optional.of(new DefaultPort(remoteDevice, PortNumber.portNumber(portNumber, remotePortName), true, annotations.build()));
}
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class PortStatisticsImpl method discoverPortStatistics.
@Override
public Collection<PortStatistics> discoverPortStatistics() {
Collection<PortStatistics> portStatistics = Lists.newArrayList();
try {
DeviceId deviceId = handler().data().deviceId();
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(deviceId);
Optional<JsonNode> result = AristaUtils.retrieveCommandResult(handler(), SHOW_INTERFACES);
if (!result.isPresent()) {
return portStatistics;
}
JsonNode interfaces = result.get().findValue(INTERFACES);
if (interfaces == null) {
return portStatistics;
}
Iterator<Map.Entry<String, JsonNode>> ifIterator = interfaces.fields();
while (ifIterator.hasNext()) {
Map.Entry<String, JsonNode> intf = ifIterator.next();
String ifName = intf.getKey();
JsonNode interfaceNode = intf.getValue();
JsonNode interfaceCounters = interfaceNode.get(INTERFACE_COUNTERS);
if (interfaceCounters == null) {
continue;
}
ports.stream().filter(Port::isEnabled).filter(port -> {
String portName = port.annotations().value(AnnotationKeys.PORT_NAME);
return portName != null && portName.equals(ifName);
}).findAny().ifPresent(port -> portStatistics.add(buildStatisticsForPort(interfaceCounters, port.number(), deviceId)));
}
} catch (Exception e) {
log.error("Exception occurred because of", e);
}
return portStatistics;
}
use of org.onosproject.net.Port 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;
}
Aggregations