2 * Copyright © 2021 AT&T and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.renderer.openroadminterface;
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.stream.IntStream;
13 import org.opendaylight.transportpce.common.mapping.PortMapping;
14 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
15 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220114.mapping.Mapping;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.attributes.rev200327.parent.odu.allocation.ParentOduAllocationBuilder;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.attributes.rev200327.parent.odu.allocation.parent.odu.allocation.trib.slots.choice.OpucnBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev200529.Off;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceKey;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev200529.Interface1Builder;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev200529.ethernet.container.EthernetBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.EthernetCsmacd;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.InterfaceType;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.OtnOdu;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODU4;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUCTP;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUTTPCTP;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.OpucnTribSlotDef;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.PayloadTypeDef;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.OduAttributes.MonitoringMode;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.odu.container.OduBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.opu.OpuBuilder;
36 import org.opendaylight.yangtools.yang.common.Uint16;
37 import org.opendaylight.yangtools.yang.common.Uint32;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 public class OpenRoadmOtnInterface710 {
42 private final PortMapping portMapping;
43 private final OpenRoadmInterfaces openRoadmInterfaces;
44 private static final Logger LOG = LoggerFactory
45 .getLogger(OpenRoadmOtnInterface710.class);
47 public OpenRoadmOtnInterface710(PortMapping portMapping,
48 OpenRoadmInterfaces openRoadmInterfaces) {
49 this.portMapping = portMapping;
50 this.openRoadmInterfaces = openRoadmInterfaces;
53 public String createOpenRoadmEth100GInterface(String nodeId,
54 String logicalConnPoint) throws OpenRoadmInterfaceException {
56 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
57 if (portMap == null) {
58 throwException(nodeId, logicalConnPoint);
61 // Ethernet interface specific data
62 EthernetBuilder ethIfBuilder = new EthernetBuilder()
64 .setSpeed(Uint32.valueOf(100000));
65 InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(
66 portMap, EthernetCsmacd.class,
67 logicalConnPoint + "-ETHERNET-100G");
68 // Create Interface1 type object required for adding as augmentation
69 Interface1Builder ethIf1Builder = new Interface1Builder();
70 ethInterfaceBldr.addAugmentation(ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
71 // Post interface on the device
72 this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
73 // Post the equipment-state change on the device circuit-pack
74 this.openRoadmInterfaces.postOTNEquipmentState(nodeId,
75 portMap.getSupportingCircuitPackName(), true);
76 this.portMapping.updateMapping(nodeId, portMap);
77 String ethernetInterfaceName = ethInterfaceBldr.getName();
79 return ethernetInterfaceName;
82 private void throwException(String nodeId, String logicalConnPoint)
83 throws OpenRoadmInterfaceException {
85 throw new OpenRoadmInterfaceException(String.format(
86 "Unable to get mapping from PortMapping for node % and logical connection port %s",
87 nodeId, logicalConnPoint));
90 public String createOpenRoadmOdu4Interface(String nodeId, String logicalConnPoint,
91 String payLoad, boolean isNetworkPort, OpucnTribSlotDef minTribSlotNumber, OpucnTribSlotDef maxTribSlotNumber)
92 throws OpenRoadmInterfaceException {
93 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
94 if (portMap == null) {
95 throwException(nodeId, logicalConnPoint);
97 List<String> supportingInterfaceList = new ArrayList<>();
98 String supportingInterface = null;
100 supportingInterface = portMap.getSupportingOducn();
101 // TODO: remove this log
102 LOG.info("ODUCn supporting interface on port mapping {}", supportingInterface);
104 supportingInterface = logicalConnPoint + "-ETHERNET-100G";
107 if (supportingInterface == null) {
108 throw new OpenRoadmInterfaceException(
109 "Interface Creation failed because of missing supported "
110 + "ODU4 on network end or Ethernet on client");
112 // Supporting interface is a list for B100G (7.1) device models
113 supportingInterfaceList.add(supportingInterface);
115 InterfaceBuilder oduIfBuilder = createGenericInterfaceBuilder(
116 portMap, OtnOdu.class, logicalConnPoint + "-ODU4")
117 .setSupportingInterfaceList(supportingInterfaceList);
118 // Agument ODU4 specific interface data
119 OduBuilder oduBuilder = new OduBuilder().setRate(ODU4.class)
120 .setOduFunction(ODUTTPCTP.class)
121 .setMonitoringMode(MonitoringMode.Terminated);
122 LOG.debug("Inside the ODU4 creation {} {} {}", isNetworkPort, minTribSlotNumber.getValue(),
123 maxTribSlotNumber.getValue());
124 // If it is a network port we have fill the required trib-slots and trib-ports
126 List<OpucnTribSlotDef> opucnTribSlotDefList = new ArrayList<>();
127 // Escape characters are used to here to take the literal dot
128 Uint16 tribPortNumber = Uint16.valueOf(minTribSlotNumber.getValue().split("\\.")[0]);
129 Uint16 startTribSlot = Uint16.valueOf(minTribSlotNumber.getValue().split("\\.")[1]);
130 Uint16 endTribSlot = Uint16.valueOf(maxTribSlotNumber.getValue().split("\\.")[1]);
132 IntStream.range(startTribSlot.intValue(), endTribSlot.intValue() + 1)
134 nbr -> opucnTribSlotDefList.add(OpucnTribSlotDef.getDefaultInstance(tribPortNumber + "." + nbr))
136 ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
137 .setTribPortNumber(tribPortNumber)
138 .setTribSlotsChoice(new OpucnBuilder().setOpucnTribSlots(opucnTribSlotDefList).build());
139 // reset the ODU function as ODUCTP and the monitoring moode
140 oduBuilder.setOduFunction(ODUCTP.class)
141 .setMonitoringMode(MonitoringMode.NotTerminated)
142 .setParentOduAllocation(parentOduAllocationBuilder.build());
145 // This is for the client side of the ODU (ODU-TTP-CTP)
146 // Set Opu attributes
147 OpuBuilder opuBuilder = new OpuBuilder()
148 .setExpPayloadType(new PayloadTypeDef(payLoad))
149 .setPayloadType(new PayloadTypeDef(payLoad));
150 oduBuilder.setOpu(opuBuilder.build());
153 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder
155 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
156 oduIfBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
157 // Post interface on the device
158 this.openRoadmInterfaces.postOTNInterface(nodeId, oduIfBuilder);
159 LOG.info("Returning the ODU4 inteface {}", oduIfBuilder.getName());
160 return oduIfBuilder.getName();
163 private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap,
164 Class<? extends InterfaceType> type, String key) {
165 return new InterfaceBuilder()
166 // .setDescription(" TBD ")
167 // .setCircuitId(" TBD ")
168 .setSupportingCircuitPackName(
169 portMap.getSupportingCircuitPackName())
170 .setSupportingPort(portMap.getSupportingPort())
171 .setAdministrativeState(AdminStates.InService)
172 // TODO get rid of unchecked cast warning
173 .setType(type).setName(key).withKey(new InterfaceKey(key));