import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.opendaylight.transportpce.common.StringConstants;
import org.opendaylight.transportpce.common.Timeouts;
import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
-import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
-import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.Network;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.NetworkBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.OpenroadmNodeVersion;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.cp.to.degree.CpToDegree;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.cp.to.degree.CpToDegreeBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.cp.to.degree.CpToDegreeKey;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.Mapping;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.MappingBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.MappingKey;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mc.capabilities.McCapabilities;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mc.capabilities.McCapabilitiesBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mc.capabilities.McCapabilitiesKey;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.Nodes;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.NodesBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.NodesKey;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.nodes.NodeInfo;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.nodes.NodeInfoBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.switching.pool.lcp.SwitchingPoolLcp;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.switching.pool.lcp.SwitchingPoolLcpBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.switching.pool.lcp.SwitchingPoolLcpKey;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.switching.pool.lcp.switching.pool.lcp.NonBlockingList;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.switching.pool.lcp.switching.pool.lcp.NonBlockingListBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.switching.pool.lcp.switching.pool.lcp.NonBlockingListKey;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.Network;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.NetworkBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.OpenroadmNodeVersion;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.cp.to.degree.CpToDegree;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.cp.to.degree.CpToDegreeBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.cp.to.degree.CpToDegreeKey;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.MappingBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.MappingKey;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mc.capabilities.McCapabilities;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mc.capabilities.McCapabilitiesBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mc.capabilities.McCapabilitiesKey;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.Nodes;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.NodesBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.NodesKey;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.nodes.NodeInfo;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.nodes.NodeInfoBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.switching.pool.lcp.SwitchingPoolLcp;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.switching.pool.lcp.SwitchingPoolLcpBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.switching.pool.lcp.SwitchingPoolLcpKey;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.switching.pool.lcp.switching.pool.lcp.NonBlockingList;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.switching.pool.lcp.switching.pool.lcp.NonBlockingListBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.switching.pool.lcp.switching.pool.lcp.NonBlockingListKey;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.FrequencyGHz;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.Direction;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.PortQual;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.XpdrNodeTypes;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.CircuitPack;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.OrgOpenroadmDeviceData;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.pack.Ports;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.pack.PortsKey;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.packs.CircuitPacks;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.port.Interfaces;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.xponder.XpdrPort;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.EthernetCsmacd;
import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.InterfaceType;
import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OpenROADMOpticalMultiplex;
import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OpticalTransport;
import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OtnOdu;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OtnOtu;
import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.Protocols1;
import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.Lldp;
import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.PortConfig;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.port.capability.rev181019.Ports1;
import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181019.SupportedIfCapability;
import org.opendaylight.yang.gen.v1.http.org.openroadm.switching.pool.types.rev191129.SwitchingPoolTypes;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
private final DataBroker dataBroker;
private final DeviceTransactionManager deviceTransactionManager;
- private final OpenRoadmInterfaces openRoadmInterfaces;
static {
SUFFIX = Map.of(
Direction.Bidirectional, "TXRX");
}
- public PortMappingVersion221(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
- OpenRoadmInterfaces openRoadmInterfaces) {
+ public PortMappingVersion221(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager) {
this.dataBroker = dataBroker;
this.deviceTransactionManager = deviceTransactionManager;
- this.openRoadmInterfaces = openRoadmInterfaces;
}
public boolean createMappingData(String nodeId) {
LOG.info(PortMappingUtils.CREATE_MAPPING_DATA_LOGMSG, nodeId, "2.2.1");
List<Mapping> portMapList = new ArrayList<>();
Map<McCapabilitiesKey, McCapabilities> mcCapabilities = new HashMap<>();
- InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
+ InstanceIdentifier<Info> infoIID = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(Info.class)
+ .build();
Optional<Info> deviceInfoOptional = this.deviceTransactionManager.getDataFromDevice(
nodeId, LogicalDatastoreType.OPERATIONAL, infoIID,
Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
// Get TTP port mapping
if (!createTtpPortMapping(nodeId, deviceInfo, portMapList)) {
// return false if mapping creation for TTP's failed
- LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "TTP's");
+ LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "TTP's");
return false;
}
// Get PP port mapping
if (!createPpPortMapping(nodeId, deviceInfo, portMapList)) {
// return false if mapping creation for PP's failed
- LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "PP's");
+ LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "PP's");
return false;
}
// Get MC capabilities
break;
case Xpdr:
if (!createXpdrPortMapping(nodeId, portMapList)) {
- LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "Xponder");
+ LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "Xponder");
return false;
}
break;
default:
LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG,
- nodeId, "create", deviceInfo.getNodeType() + " - unknown nodetype");
+ nodeId, PortMappingUtils.CREATE, deviceInfo.getNodeType() + " - unknown nodetype");
break;
}
public boolean updateMapping(String nodeId, Mapping oldMapping) {
if (nodeId == null) {
- LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, "node id null" , "update", "a null value");
+ LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, "node id null" , PortMappingUtils.UPDATE, "a null value");
return false;
}
if (oldMapping == null) {
- LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "update", "a null value");
+ LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.UPDATE, "a null value");
return false;
}
- InstanceIdentifier<Ports> portId = InstanceIdentifier.create(OrgOpenroadmDevice.class)
- .child(CircuitPacks.class, new CircuitPacksKey(oldMapping.getSupportingCircuitPackName()))
- .child(Ports.class, new PortsKey(oldMapping.getSupportingPort()));
+ InstanceIdentifier<Ports> portId = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(CircuitPacks.class, new CircuitPacksKey(oldMapping.getSupportingCircuitPackName()))
+ .child(Ports.class, new PortsKey(oldMapping.getSupportingPort()))
+ .build();
try {
Ports port = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL,
portId, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).get();
return true;
} catch (InterruptedException | ExecutionException e) {
LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG,
- nodeId, "update", oldMapping.getLogicalConnectionPoint(), e);
+ nodeId, PortMappingUtils.UPDATE, oldMapping.getLogicalConnectionPoint(), e);
return false;
}
}
private boolean createXpdrPortMapping(String nodeId, List<Mapping> portMapList) {
// Creating for Xponder Line and Client Ports
- InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+ OrgOpenroadmDevice device = getXpdrDevice(nodeId);
+ if (device == null) {
+ return false;
+ }
+ Map<String, String> lcpMap = new HashMap<>();
+ Map<String, Mapping> mappingMap = new HashMap<>();
+ getXpdrMaps(device, nodeId, lcpMap, mappingMap);
+ if (device.getConnectionMap() == null) {
+ LOG.warn(PortMappingUtils.NO_CONMAP_LOGMSG, nodeId);
+ } else {
+ for (ConnectionMap cm : device.nonnullConnectionMap().values()) {
+ String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
+ Destination destination0 = cm.nonnullDestination().values().iterator().next();
+ String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
+ if (!lcpMap.containsKey(skey)) {
+ LOG.error(PortMappingUtils.CONMAP_ISSUE_LOGMSG, nodeId, skey, dkey);
+ continue;
+ }
+ String slcp = lcpMap.get(skey);
+ Mapping mapping = mappingMap.get(slcp);
+ mappingMap.remove(slcp);
+ portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping,
+ //dlcp
+ lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null,
+ null));
+ }
+ }
+ if (device.getOduSwitchingPools() != null) {
+ postPortMapping(nodeId, null, null, null, getSwitchingPoolList(device, lcpMap, nodeId), null);
+ }
+ mappingMap.forEach((k,v) -> portMapList.add(v));
+ return true;
+ }
+
+ private OrgOpenroadmDevice getXpdrDevice(String nodeId) {
+ InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .build();
Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
LogicalDatastoreType.OPERATIONAL, deviceIID,
Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
if (deviceObject.isEmpty()) {
LOG.error(PortMappingUtils.CANNOT_GET_DEV_CONF_LOGMSG, nodeId);
- return false;
+ return null;
}
OrgOpenroadmDevice device = deviceObject.get();
if (device.getCircuitPacks() == null) {
- LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, "found");
- return false;
+ LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, PortMappingUtils.FOUND);
+ return null;
}
+ return device;
+ }
- Map<String, String> lcpMap = new HashMap<>();
- Map<String, Mapping> mappingMap = new HashMap<>();
+ private void getXpdrMaps(OrgOpenroadmDevice device, String nodeId,
+ Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
List<CircuitPacks> circuitPackList = new ArrayList<>(device.nonnullCircuitPacks().values());
circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName));
if (device.getXponder() == null) {
for (CircuitPacks cp : circuitPackList) {
String circuitPackName = cp.getCircuitPackName();
if (cp.getPorts() == null) {
- LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, "found", circuitPackName);
+ LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName);
continue;
}
List<Ports> portList = new ArrayList<>(cp.nonnullPorts().values());
portList.sort(Comparator.comparing(Ports::getPortName));
for (Ports port : portList) {
int[] counters = fillXpdrLcpsMaps(line, client, nodeId,
- 1, null, circuitPackName, port,
+ 1, XpdrNodeTypes.Tpdr, circuitPackName, port,
circuitPackList, lcpMap, mappingMap);
line = counters[0];
client = counters[1];
}
}
} else {
- LOG.info(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, "found");
- for (Xponder xponder : deviceObject.get().nonnullXponder().values()) {
+ LOG.info(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, PortMappingUtils.FOUND);
+ for (Xponder xponder : device.nonnullXponder().values()) {
// Variables to keep track of number of line ports and client ports
int line = 1;
int client = 1;
XpdrNodeTypes xponderType = xponder.getXpdrType();
for (XpdrPort xpdrPort : xponder.nonnullXpdrPort().values().stream()
.sorted((xp1, xp2) -> xp1.getIndex().compareTo(xp2.getIndex())).collect(Collectors.toList())) {
- String circuitPackName = xpdrPort.getCircuitPackName();
- String portName = xpdrPort.getPortName();
- // If there xponder-subtree has missing circuit-packs or ports,
- // This gives a null-pointer expection,
- Optional<CircuitPacks> cpList = device.nonnullCircuitPacks().values().stream()
- .filter(cp -> cp.getCircuitPackName().equals(circuitPackName)).findFirst();
- if (cpList.isEmpty()) {
- LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
- nodeId, circuitPackName);
- continue;
- }
- Optional<Ports> portsList = cpList.get().nonnullPorts().values().stream()
- .filter(p -> p.getPortName().equals(portName)).findFirst();
- if (portsList.isEmpty()) {
- LOG.warn(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
- nodeId, portName, circuitPackName, "in the device");
+ Ports port = getXpdrPorts(device, xpdrPort, nodeId);
+ if (port == null) {
continue;
}
int[] counters = fillXpdrLcpsMaps(line, client, nodeId,
- xponderNb, xponderType, circuitPackName, portsList.get(),
+ xponderNb, xponderType, xpdrPort.getCircuitPackName(), port,
circuitPackList, lcpMap, mappingMap);
line = counters[0];
client = counters[1];
}
}
}
+ }
- if (device.getConnectionMap() == null) {
- LOG.warn(PortMappingUtils.NO_CONMAP_LOGMSG, nodeId);
- } else {
- for (ConnectionMap cm : deviceObject.get().nonnullConnectionMap().values()) {
- String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
- Destination destination0 = cm.nonnullDestination().values().iterator().next();
- String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
- if (!lcpMap.containsKey(skey)) {
- LOG.error(PortMappingUtils.CONMAP_ISSUE_LOGMSG, nodeId, skey, dkey);
- continue;
- }
- String slcp = lcpMap.get(skey);
- Mapping mapping = mappingMap.get(slcp);
- mappingMap.remove(slcp);
- portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping,
- //dlcp
- lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null,
- null));
- }
+ private Ports getXpdrPorts(OrgOpenroadmDevice device, XpdrPort xpdrPort, String nodeId) {
+ String circuitPackName = xpdrPort.getCircuitPackName();
+ String portName = xpdrPort.getPortName();
+ // If there xponder-subtree has missing circuit-packs or ports,
+ // This gives a null-pointer expection,
+ Optional<CircuitPacks> cpList = device.nonnullCircuitPacks().values().stream()
+ .filter(cp -> cp.getCircuitPackName().equals(circuitPackName)).findFirst();
+ if (cpList.isEmpty()) {
+ LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
+ nodeId, circuitPackName);
+ return null;
}
+ Optional<Ports> portsList = cpList.get().nonnullPorts().values().stream()
+ .filter(p -> p.getPortName().equals(portName)).findFirst();
+ if (portsList.isEmpty()) {
+ LOG.warn(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
+ nodeId, portName, circuitPackName, "in the device");
+ return null;
+ }
+ return portsList.get();
+ }
- if (device.getOduSwitchingPools() != null) {
- List<SwitchingPoolLcp> switchingPoolList = new ArrayList<>();
- for (OduSwitchingPools odp : device.nonnullOduSwitchingPools().values()) {
- Map<NonBlockingListKey,NonBlockingList> nbMap = new HashMap<>();
- for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org
- .openroadm.device.odu.switching.pools.NonBlockingList nbl : odp.nonnullNonBlockingList().values()) {
- if (nbl.getPortList() == null) {
+ private List<SwitchingPoolLcp> getSwitchingPoolList(OrgOpenroadmDevice device,
+ Map<String, String> lcpMap, String nodeId) {
+ List<SwitchingPoolLcp> switchingPoolList = new ArrayList<>();
+ for (OduSwitchingPools odp : device.nonnullOduSwitchingPools().values()) {
+ Map<NonBlockingListKey,NonBlockingList> nbMap = new HashMap<>();
+ for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org
+ .openroadm.device.odu.switching.pools.NonBlockingList nbl : odp.nonnullNonBlockingList().values()) {
+ if (nbl.getPortList() == null) {
+ continue;
+ }
+ Set<String> lcpList = new HashSet<>();
+ for (PortList item : nbl.nonnullPortList().values()) {
+ String key = item.getCircuitPackName() + "+" + item.getPortName();
+ if (!lcpMap.containsKey(key)) {
+ LOG.error(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG,
+ nodeId, item.getPortName(), item.getCircuitPackName(), "to a logical connection point");
continue;
}
- List<String> lcpList = new ArrayList<>();
- for (PortList item : nbl.nonnullPortList().values()) {
- String key = item.getCircuitPackName() + "+" + item.getPortName();
- if (!lcpMap.containsKey(key)) {
- LOG.error(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG,
- nodeId, item.getPortName(), item.getCircuitPackName(), "to a logical connection point");
- continue;
- }
- lcpList.add(lcpMap.get(key));
- }
- NonBlockingList nonBlockingList = new NonBlockingListBuilder()
- .setNblNumber(nbl.getNblNumber())
- .setInterconnectBandwidth(nbl.getInterconnectBandwidth())
- .setInterconnectBandwidthUnit(nbl.getInterconnectBandwidthUnit())
- .setLcpList(lcpList)
- .build();
- nbMap.put(nonBlockingList.key(), nonBlockingList);
+ lcpList.add(lcpMap.get(key));
}
- SwitchingPoolLcp splBldr = new SwitchingPoolLcpBuilder()
+ NonBlockingList nonBlockingList = new NonBlockingListBuilder()
+ .setNblNumber(nbl.getNblNumber())
+ .setInterconnectBandwidth(nbl.getInterconnectBandwidth())
+ .setInterconnectBandwidthUnit(nbl.getInterconnectBandwidthUnit())
+ .setLcpList(lcpList)
+ .build();
+ nbMap.put(nonBlockingList.key(), nonBlockingList);
+ }
+ switchingPoolList.add(
+ new SwitchingPoolLcpBuilder()
.setSwitchingPoolNumber(odp.getSwitchingPoolNumber())
.setSwitchingPoolType(SwitchingPoolTypes.forValue(odp.getSwitchingPoolType().getIntValue()))
.setNonBlockingList(nbMap)
- .build();
- switchingPoolList.add(splBldr);
- }
- postPortMapping(nodeId, null, null, null, switchingPoolList, null);
+ .build());
}
-
- mappingMap.forEach((k,v) -> portMapList.add(v));
- return true;
+ return switchingPoolList;
}
private boolean checkPartnerPortNotNull(Ports port) {
List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks> srgCps
= new ArrayList<>();
LOG.debug(PortMappingUtils.GETTING_CP_LOGMSG, deviceId, srgCounter);
- InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
- .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter)));
+ InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter)))
+ .build();
Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
LogicalDatastoreType.OPERATIONAL, srgIID,
Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
for (Entry<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks>>
srgCpEntry : getSrgCps(nodeId, deviceInfo).entrySet()) {
List<String> keys = new ArrayList<>();
+ int portIndex = 1;
for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks
cp : srgCpEntry.getValue()) {
String circuitPackName = cp.getCircuitPackName();
List<Ports> portList = getPortList(circuitPackName, nodeId);
Collections.sort(portList, new SortPort221ByName());
- int portIndex = 1;
for (Ports port : portList) {
if (!checkPortQual(port, circuitPackName, nodeId)) {
continue;
break;
case Rx:
case Tx:
- if (!checkPartnerPortNotNull(port)) {
- LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG
- + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
- nodeId, port.getPortName(), circuitPackName);
+ Ports port2 = getPartnerPort(port, circuitPackName, nodeId);
+ if (port2 == null) {
continue;
}
String lcp1 = createLogicalConnectionPort(port, srgCpEntry.getKey(), portIndex);
LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
nodeId, port.getPortName(), circuitPackName, lcp1);
- InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
- .child(CircuitPacks.class,
- new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
- .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName()));
- Optional<Ports> port2Object = this.deviceTransactionManager
- .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port2ID,
- Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
- if (port2Object.isEmpty()
- || port2Object.get().getPortQual().getIntValue()
- != PortQual.RoadmExternal.getIntValue()) {
- LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG
- + PortMappingUtils.PARTNERPORT_GET_ERROR_LOGMSG,
- nodeId, port.getPartnerPort().getPortName(),
- port.getPartnerPort().getCircuitPackName(),
- port.getPortName(), circuitPackName);
- continue;
- }
- Ports port2 = port2Object.get();
- if (!checkPartnerPort(circuitPackName, port, port2)) {
- LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG
- + PortMappingUtils.PARTNERPORT_CONF_ERROR_LOGMSG,
- nodeId, port2.getPortName(), port.getPartnerPort().getCircuitPackName(),
- port.getPortName(), circuitPackName);
- portIndex++;
- continue;
- }
String lcp2 = createLogicalConnectionPort(port2, srgCpEntry.getKey(),portIndex);
LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
nodeId, port2.getPortName(), circuitPackName, lcp2);
return true;
}
+ private Ports getPartnerPort(Ports port, String circuitPackName, String nodeId) {
+ if (!checkPartnerPortNotNull(port)) {
+ LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
+ nodeId, port.getPortName(), circuitPackName);
+ return null;
+ }
+ InstanceIdentifier<Ports> port2ID = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(CircuitPacks.class, new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
+ .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName()))
+ .build();
+ Optional<Ports> port2Object = this.deviceTransactionManager
+ .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port2ID,
+ Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+ if (port2Object.isEmpty()
+ || port2Object.get().getPortQual().getIntValue() != PortQual.RoadmExternal.getIntValue()) {
+ LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_GET_ERROR_LOGMSG,
+ nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName(),
+ port.getPortName(), circuitPackName);
+ return null;
+ }
+ Ports port2 = port2Object.get();
+ if (!checkPartnerPort(circuitPackName, port, port2)) {
+ LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_CONF_ERROR_LOGMSG,
+ nodeId, port2.getPortName(), port.getPartnerPort().getCircuitPackName(),
+ port.getPortName(), circuitPackName);
+ //TODO check if we really needed to increment portIndex in this condition
+ // if yes this block should not be in getPartnerPort and must move back to createPpPortMapping
+ return null;
+ }
+ return port2;
+ }
+
private List<Ports> getPortList(String circuitPackName, String nodeId) {
- InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
- .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
+ InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName))
+ .build();
Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
LogicalDatastoreType.OPERATIONAL, cpIID,
Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
return new ArrayList<>();
}
if (circuitPackObject.get().getPorts() == null) {
- LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, "found", circuitPackName);
+ LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName);
return new ArrayList<>();
}
return new ArrayList<>(circuitPackObject.get().nonnullPorts().values());
return null;
}
+ @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+ value = "SLF4J_UNKNOWN_ARRAY",
+ justification = "False positive")
private Map<Integer, Degree> getDegreesMap(String deviceId, Info ordmInfo) {
Map<Integer, Degree> degrees = new HashMap<>();
for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
LOG.debug(PortMappingUtils.GETTING_CONPORT_LOGMSG, deviceId, degreeCounter);
- InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
- .child(Degree.class, new DegreeKey(Uint16.valueOf(degreeCounter)));
+ InstanceIdentifier<Degree> deviceIID = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(Degree.class, new DegreeKey(Uint16.valueOf(degreeCounter)))
+ .build();
Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
LogicalDatastoreType.OPERATIONAL, deviceIID,
Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
// if not present assume to be 20 (temporary)
Integer maxSrg = ordmInfo.getMaxSrgs() == null ? 20 : ordmInfo.getMaxSrgs().toJava();
for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
- InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
- .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter)));
+ InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter)))
+ .build();
Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
LogicalDatastoreType.OPERATIONAL, srgIID,
Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
private Map<String, String> getEthInterfaceList(String nodeId) {
LOG.info(PortMappingUtils.GETTING_ETH_LIST_LOGMSG, nodeId);
- InstanceIdentifier<Protocols> protocoliid = InstanceIdentifier.create(OrgOpenroadmDevice.class)
- .child(Protocols.class);
+ InstanceIdentifier<Protocols> protocoliid = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(Protocols.class)
+ .build();
Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
LogicalDatastoreType.OPERATIONAL, protocoliid, Timeouts.DEVICE_READ_TIMEOUT,
Timeouts.DEVICE_READ_TIMEOUT_UNIT);
if (!portConfig.getAdminStatus().equals(PortConfig.AdminStatus.Txandrx)) {
continue;
}
- InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
- .child(Interface.class, new InterfaceKey(portConfig.getIfName()));
+ InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(Interface.class, new InterfaceKey(portConfig.getIfName()))
+ .build();
Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
Timeouts.DEVICE_READ_TIMEOUT_UNIT);
}
String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
cpToInterfaceMap.put(supportingCircuitPackName, portConfig.getIfName());
- InstanceIdentifier<CircuitPacks> circuitPacksIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
- .child(CircuitPacks.class, new CircuitPacksKey(supportingCircuitPackName));
+ InstanceIdentifier<CircuitPacks> circuitPacksIID = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(CircuitPacks.class, new CircuitPacksKey(supportingCircuitPackName))
+ .build();
Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
Timeouts.DEVICE_READ_TIMEOUT_UNIT);
nodesList.put(nodes.key(),nodes);
Network network = new NetworkBuilder().setNodes(nodesList).build();
-
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
InstanceIdentifier<Network> nodesIID = InstanceIdentifier.builder(Network.class).build();
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network);
private Mapping updateMappingObject(String nodeId, Ports port, Mapping oldmapping) {
MappingBuilder mpBldr = new MappingBuilder(oldmapping);
updateMappingStates(mpBldr, port, oldmapping);
- if ((port.getInterfaces() == null)
- || (!oldmapping.getLogicalConnectionPoint().contains(StringConstants.TTP_TOKEN)
- && !oldmapping.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN))) {
+ if (port.getInterfaces() == null) {
return mpBldr.build();
}
// Get interfaces provisioned on the port
}
private MappingBuilder updateMappingInterfaces(String nodeId, MappingBuilder mpBldr, Ports port) {
+ mpBldr.setSupportingOtu4(null)
+ .setSupportingOdu4(null);
for (Interfaces interfaces : port.getInterfaces()) {
- try {
- Optional<Interface> openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId,
- interfaces.getInterfaceName());
- if (openRoadmInterface.isEmpty()) {
- LOG.warn(PortMappingUtils.INTF_ISSUE_LOGMSG,
- nodeId, interfaces.getInterfaceName() + "- empty interface");
- continue;
- }
- LOG.debug(PortMappingUtils.GOT_INTF_LOGMSG,
- nodeId, openRoadmInterface.get().getName(), openRoadmInterface.get().getType());
- Class<? extends InterfaceType> interfaceType
- = (Class<? extends InterfaceType>) openRoadmInterface.get().getType();
- // Check if interface type is OMS or OTS
- if (interfaceType.equals(OpenROADMOpticalMultiplex.class)) {
- mpBldr.setSupportingOms(interfaces.getInterfaceName());
- }
- if (interfaceType.equals(OpticalTransport.class)) {
- mpBldr.setSupportingOts(interfaces.getInterfaceName());
- }
- if (interfaceType.equals(OtnOdu.class)) {
- mpBldr.setSupportingOdu4(interfaces.getInterfaceName());
- }
- } catch (OpenRoadmInterfaceException ex) {
- LOG.warn(PortMappingUtils.INTF_ISSUE_LOGMSG, nodeId, interfaces.getInterfaceName(), ex);
+ Optional<Interface> openRoadmInterface = getInterfaceFromDevice(nodeId,
+ interfaces.getInterfaceName());
+ if (openRoadmInterface.isEmpty()) {
+ LOG.warn(PortMappingUtils.INTF_ISSUE_LOGMSG,
+ nodeId, interfaces.getInterfaceName() + "- empty interface");
+ continue;
+ }
+ LOG.debug(PortMappingUtils.GOT_INTF_LOGMSG,
+ nodeId, openRoadmInterface.get().getName(), openRoadmInterface.get().getType());
+ Class<? extends InterfaceType> interfaceType
+ = (Class<? extends InterfaceType>) openRoadmInterface.get().getType();
+ // Check if interface type is OMS or OTS
+ if (interfaceType.equals(OpenROADMOpticalMultiplex.class)) {
+ mpBldr.setSupportingOms(interfaces.getInterfaceName());
+ }
+ if (interfaceType.equals(OpticalTransport.class)) {
+ mpBldr.setSupportingOts(interfaces.getInterfaceName());
+ }
+ if (interfaceType.equals(OtnOtu.class)) {
+ mpBldr.setSupportingOtu4(interfaces.getInterfaceName());
+ }
+ if (interfaceType.equals(OtnOdu.class)) {
+ mpBldr.setSupportingOdu4(interfaces.getInterfaceName());
+ }
+ if (interfaceType.equals(EthernetCsmacd.class)) {
+ mpBldr.setSupportingEthernet(interfaces.getInterfaceName());
}
}
return mpBldr;
private Mapping createNewXpdrMapping(String nodeId, Ports port, String circuitPackName,
String logicalConnectionPoint, String partnerLcp, XpdrNodeTypes xpdrNodeType) {
+ Set<Class<? extends org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211
+ .SupportedIfCapability>> supportedIntf = new HashSet<>();
+ for (String sup: getSupIfCapList(port)) {
+ if (MappingUtilsImpl.convertSupIfCapa(sup) != null) {
+ supportedIntf.add(MappingUtilsImpl.convertSupIfCapa(sup));
+ }
+ }
MappingBuilder mpBldr = new MappingBuilder()
.withKey(new MappingKey(logicalConnectionPoint))
.setLogicalConnectionPoint(logicalConnectionPoint)
.setSupportingCircuitPackName(circuitPackName)
.setSupportingPort(port.getPortName())
.setPortDirection(port.getPortDirection().getName())
- .setLcpHashVal(PortMappingUtils.fnv1size64(nodeId + "-" + logicalConnectionPoint));
+ .setLcpHashVal(PortMappingUtils.fnv1size64(nodeId + "-" + logicalConnectionPoint))
+ .setSupportedInterfaceCapability(supportedIntf);
if (port.getPortQual() != null) {
mpBldr.setPortQual(port.getPortQual().getName());
}
if (partnerLcp != null) {
mpBldr.setPartnerLcp(partnerLcp);
}
- if (port.getSupportedInterfaceCapability() != null) {
- List<Class<? extends org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327
- .SupportedIfCapability>> supportedIntf = new ArrayList<>();
- for (Class<? extends SupportedIfCapability> sup: port.getSupportedInterfaceCapability()) {
- supportedIntf.add(MappingUtilsImpl.convertSupIfCapa(sup.getSimpleName()));
- }
- mpBldr.setSupportedInterfaceCapability(supportedIntf);
- }
if (port.getAdministrativeState() != null) {
mpBldr.setPortAdminState(port.getAdministrativeState().name());
}
return mpBldr.build();
}
+ private List<String> getSupIfCapList(Ports port) {
+ Set<Class<? extends SupportedIfCapability>> supIfCapClassList = port.getSupportedInterfaceCapability();
+ if (supIfCapClassList != null) {
+ return supIfCapClassList
+ .stream().map(e -> e.getSimpleName())
+ .collect(Collectors.toList());
+ }
+ Ports1 ports1 = port.augmentation(Ports1.class);
+ if (ports1 != null && ports1.getPortCapabilities() != null) {
+ return ports1.getPortCapabilities().getSupportedInterfaceCapability()
+ .values().stream().map(e -> e.getIfCapType().getSimpleName())
+ .collect(Collectors.toList());
+ }
+ return Collections.emptyList();
+ }
+
private Ports getPort2(Ports port, String nodeId, String circuitPackName, StringBuilder circuitPackName2,
//circuitPackName2 will be updated by reference contrary to circuitPackName
List<CircuitPacks> circuitPackList, Map<String, String> lcpMap) {
PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, client, StringConstants.CLIENT_TOKEN);
lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp0);
mappingMap.put(lcp0,
- createXpdrMappingObject(nodeId, port, circuitPackName, lcp0, null, null, null, null));
+ createXpdrMappingObject(nodeId, port, circuitPackName, lcp0, null, null, null, xponderType));
client++;
break;
switch (cpMapValue.size()) {
case 1:
// port is bidirectional
- InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
- .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
- .child(Ports.class, new PortsKey(cp1.getPortName()));
- LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
- Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
- LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
- Timeouts.DEVICE_READ_TIMEOUT_UNIT);
- if (portObject.isEmpty()) {
- LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
+ Ports port = getTtpPort(cp1, cp1Name, nodeId);
+ if (port == null) {
return false;
}
- Ports port = portObject.get();
if (!checkTtpPort(port, cp1Name, nodeId, true)) {
continue;
}
-
String logicalConnectionPoint =
PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(), "TXRX");
LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
break;
case 2:
// ports are unidirectionals
- ConnectionPorts cp2 = cpMapValue.get(1);
- String cp2Name = cp2.getCircuitPackName();
- InstanceIdentifier<Ports> port1ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
- .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
- .child(Ports.class, new PortsKey(cp1.getPortName()));
- LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
- Optional<Ports> port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
- LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT,
- Timeouts.DEVICE_READ_TIMEOUT_UNIT);
- InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
- .child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
- .child(Ports.class, new PortsKey(cp2.getPortName()));
- LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp2.getPortName(), cp2Name);
- Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
- LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
- Timeouts.DEVICE_READ_TIMEOUT_UNIT);
- if (port1Object.isEmpty()) {
- LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
+ Ports port1 = getTtpPort(cp1, cp1Name, nodeId);
+ if (port1 == null) {
return false;
}
- if (port2Object.isEmpty()) {
- LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp2.getPortName(), cp2Name);
+ ConnectionPorts cp2 = cpMapValue.get(1);
+ String cp2Name = cp2.getCircuitPackName();
+ Ports port2 = getTtpPort(cp2, cp2Name, nodeId);
+ if (port2 == null) {
return false;
}
-
- Ports port1 = port1Object.get();
- if (!checkTtpPort(port1, cp1Name, nodeId, false)) {
+ if (!checkTtpPortsUnidir(port1, port2, cp1Name, cp2Name, nodeId)) {
continue;
}
- Ports port2 = port2Object.get();
- if (!checkTtpPort(port2, cp2Name, nodeId, false)) {
- continue;
- }
-
- if (!checkPartnerPort(cp1Name, port1, port2)) {
- LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
- nodeId, port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
- continue;
- }
- // Directions checks are the same for cp1 and cp2, no need to check them twice.
- if (!checkPartnerPortNoDir(cp2Name, port2, port1)) {
- LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
- nodeId, port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
- continue;
- }
-
String logicalConnectionPoint1 = PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(),
port1.getPortDirection().getName().toUpperCase(Locale.getDefault()));
LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
default:
LOG.error(PortMappingUtils.NOT_CORRECT_CONPORT_LOGMSG, nodeId, cpMapEntry.getKey());
continue;
+ //TODO should it be continue or return false ?
}
}
return true;
}
+ private Ports getTtpPort(ConnectionPorts cp, String cpName, String nodeId) {
+ InstanceIdentifier<Ports> portID = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(CircuitPacks.class, new CircuitPacksKey(cpName))
+ .child(Ports.class, new PortsKey(cp.getPortName()))
+ .build();
+ LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp.getPortName(), cpName);
+ Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
+ LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
+ Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+ if (portObject.isEmpty()) {
+ LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp.getPortName(), cpName);
+ return null;
+ }
+ return portObject.get();
+ }
+
private boolean checkPortQual(Ports port, String cpName, String nodeId) {
if (port.getPortQual() == null) {
return false;
return true;
}
- private NodeInfo createNodeInfo(Info deviceInfo) {
+ private boolean checkTtpPortsUnidir(Ports port1, Ports port2, String cp1Name, String cp2Name, String nodeId) {
+ if (!checkTtpPort(port1, cp1Name, nodeId, false)) {
+ return false;
+ }
+ if (!checkTtpPort(port2, cp2Name, nodeId, false)) {
+ return false;
+ }
+ if (!checkPartnerPort(cp1Name, port1, port2)) {
+ LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
+ nodeId, port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
+ return false;
+ }
+ // Directions checks are the same for cp1 and cp2, no need to check them twice.
+ if (!checkPartnerPortNoDir(cp2Name, port2, port1)) {
+ LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
+ nodeId, port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
+ return false;
+ }
+ return true;
+ }
+ private NodeInfo createNodeInfo(Info deviceInfo) {
if (deviceInfo.getNodeType() == null) {
// TODO make mandatory in yang
LOG.error(PortMappingUtils.NODE_TYPE_LOGMSG, deviceInfo.getNodeId(), "field missing");
return null;
}
-
NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder()
.setOpenroadmVersion(OpenroadmNodeVersion._221)
.setNodeClli(
if (deviceInfo.getIpAddress() != null) {
nodeInfoBldr.setNodeIpAddress(deviceInfo.getIpAddress());
}
-
return nodeInfoBldr.build();
}
+ private Optional<Interface> getInterfaceFromDevice(String nodeId, String interfaceName) {
+ InstanceIdentifier<Interface> interfacesIID = InstanceIdentifier
+ .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
+ .child(Interface.class, new InterfaceKey(interfaceName))
+ .build();
+ return deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION,
+ interfacesIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+ }
}