187c842cb4966600a123dce8cdfd66fbe79a35ff
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / openroadminterface / OpenRoadmOTNInterface.java
1 /*
2  * Copyright © 2019 AT&T and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.renderer.openroadminterface;
9
10 import java.util.ArrayList;
11 import java.util.List;
12 import org.opendaylight.transportpce.common.mapping.PortMapping;
13 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
14 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200128.network.nodes.Mapping;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceBuilder;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceKey;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev171215.AdminStates;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.EthAttributes;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.Interface1;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.Interface1Builder;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.ethernet.container.EthernetBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.EthernetCsmacd;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.InterfaceType;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.OtnOdu;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODU0;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODU2;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODU2e;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODUCTP;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODUTTPCTP;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.PayloadTypeDef;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.OduAttributes;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.odu.container.OduBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.opu.OpuBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.parent.odu.allocation.ParentOduAllocationBuilder;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39
40 public class OpenRoadmOTNInterface {
41
42     private final PortMapping portMapping;
43     private final OpenRoadmInterfaces openRoadmInterfaces;
44     private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmInterfaceFactory.class);
45
46     public  OpenRoadmOTNInterface(PortMapping portMapping, OpenRoadmInterfaces openRoadmInterfaces) {
47         this.portMapping = portMapping;
48         this.openRoadmInterfaces = openRoadmInterfaces;
49     }
50
51     public String createOpenRoadmEth1GInterface(String nodeId, String logicalConnPoint)
52             throws OpenRoadmInterfaceException {
53         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
54         if (portMap == null) {
55             throw new OpenRoadmInterfaceException(String.format("Unable to get mapping from PortMapping for node % and"
56                     + " logical connection port %s", nodeId, logicalConnPoint));
57         }
58
59         // Ethernet interface specific data
60         EthernetBuilder ethIfBuilder = new EthernetBuilder()
61             .setAutoNegotiation(EthAttributes.AutoNegotiation.Disabled)
62             .setSpeed(1000L)
63             .setMtu(9000L);
64             //.setCurrSpeed("1000L")
65             //.setCurrDuplex("FULL");
66         InterfaceBuilder ethInterfaceBldr =
67             createGenericInterfaceBuilder(portMap, EthernetCsmacd.class, logicalConnPoint + "-ETHERNET1G");
68         // Create Interface1 type object required for adding as augmentation
69         Interface1Builder ethIf1Builder = new  Interface1Builder();
70         ethInterfaceBldr.addAugmentation(Interface1.class, 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, portMap.getSupportingCircuitPackName(), true);
75         this.portMapping.updateMapping(nodeId,portMap);
76         String ethernetInterfaceName = ethInterfaceBldr.getName();
77
78         return ethernetInterfaceName;
79     }
80
81     private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap,
82         Class<? extends InterfaceType> type, String key) {
83         InterfaceBuilder interfaceBuilder = new InterfaceBuilder()
84             //.setDescription("  TBD   ")
85             //.setCircuitId("   TBD    ")
86             .setSupportingCircuitPackName(portMap.getSupportingCircuitPackName())
87             .setSupportingPort(portMap.getSupportingPort())
88             .setAdministrativeState(AdminStates.InService)
89             //TODO get rid of unchecked cast warning
90             .setType(
91                 (Class<? extends org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.InterfaceType>)
92                 type
93             )
94             .setName(key)
95             .withKey(new InterfaceKey(key));
96         return interfaceBuilder;
97     }
98
99     public String createOpenRoadmEth10GInterface(String nodeId, String logicalConnPoint)
100             throws OpenRoadmInterfaceException {
101         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
102         if (portMap == null) {
103             throw new OpenRoadmInterfaceException(
104                 String.format(
105                     "Unable to get mapping from PortMapping for node % and logical connection port %s",
106                     nodeId, logicalConnPoint));
107         }
108
109         // Ethernet interface specific data
110         EthernetBuilder ethIfBuilder = new EthernetBuilder()
111             .setAutoNegotiation(EthAttributes.AutoNegotiation.Disabled)
112             .setSpeed(10000L)
113             .setMtu(9000L);
114             //.setCurrSpeed("1000L")
115             //.setCurrDuplex("FULL");
116         // Create Interface1 type object required for adding as augmentation
117         Interface1Builder ethIf1Builder = new  Interface1Builder();
118         InterfaceBuilder ethInterfaceBldr =
119             createGenericInterfaceBuilder(portMap, EthernetCsmacd.class, logicalConnPoint + "-ETHERNET10G")
120             .addAugmentation(Interface1.class, ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
121         // Post interface on the device
122         this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
123         // Post the equipment-state change on the device circuit-pack
124         this.openRoadmInterfaces.postOTNEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
125         this.portMapping.updateMapping(nodeId,portMap);
126         String ethernetInterfaceName = ethInterfaceBldr.getName();
127
128         return ethernetInterfaceName;
129     }
130
131
132     public String createOpenRoadmOdu2eInterface(String nodeId, String logicalConnPoint, String serviceName,
133             String payLoad, boolean isNetworkPort)
134             throws OpenRoadmInterfaceException {
135         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
136         if (portMap == null) {
137             throw new OpenRoadmInterfaceException(
138                 String.format("Unable to get mapping from PortMapping for node % and logical connection port %s",
139                     nodeId, logicalConnPoint));
140         }
141         String supportingInterface = null;
142
143         if (isNetworkPort) {
144             supportingInterface = portMap.getSupportingOdu4();
145
146         } else {
147             // supportingInterface = portMap.getSupportingEthernet();
148             supportingInterface = logicalConnPoint + "-ETHERNET10G";
149         }
150         InterfaceBuilder oduInterfaceBldr =
151             createGenericInterfaceBuilder(portMap, OtnOdu.class, logicalConnPoint + "-ODU2e-" + serviceName)
152                 .setSupportingInterface(supportingInterface);
153
154         // ODU interface specific data
155         OduBuilder oduIfBuilder = new OduBuilder()
156             .setRate(ODU2e.class)
157             .setOduFunction(ODUTTPCTP.class)
158             .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
159         if (isNetworkPort) {
160             List<Integer> tribSlots = new ArrayList<>();
161             //add trib slots
162             tribSlots.add(45);
163             ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
164                 //set trib port numbers
165                 .setTribPortNumber(24)
166                 .setTribSlots(tribSlots);
167             oduIfBuilder.setOduFunction(ODUCTP.class)
168                     .setMonitoringMode(OduAttributes.MonitoringMode.NotTerminated)
169                     .setParentOduAllocation(parentOduAllocationBuilder.build());
170         }
171         else {
172             // Set Opu attributes
173             OpuBuilder opuBldr = new OpuBuilder()
174                 .setPayloadType(new PayloadTypeDef(payLoad))
175                 .setExpPayloadType(new PayloadTypeDef(payLoad));
176                 //.setRxPayloadType("07")
177                 //.setPayloadInterface(payLoad);
178             oduIfBuilder.setOpu(opuBldr.build());
179         }
180         // Create Interface1 type object required for adding as augmentation
181         // TODO look at imports of different versions of class
182         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder oduIf1Builder =
183             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
184         oduInterfaceBldr.addAugmentation(
185                 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
186                 oduIf1Builder.setOdu(oduIfBuilder.build()).build());
187
188         // Post interface on the device
189         this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
190         LOG.info("returning the ODU2e inteface {}", oduInterfaceBldr.getName());
191         return oduInterfaceBldr.getName();
192     }
193
194     public String createOpenRoadmOdu0Interface(String nodeId, String logicalConnPoint, String serviceName,
195         String payLoad, boolean isNetworkPort, int tribPortNumber, int tribSlot)
196             throws OpenRoadmInterfaceException {
197         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
198         String supportingInterface = null;
199
200         if (isNetworkPort) {
201             supportingInterface = portMap.getSupportingOdu4();
202         } else {
203             // supportingInterface = portMap.getSupportingEthernet();
204             supportingInterface = logicalConnPoint + "-ETHERNET1G";
205         }
206         if (portMap == null) {
207             throw new OpenRoadmInterfaceException(
208                 String.format("Unable to get mapping from PortMapping for node % and logical connection port %s",
209                     nodeId, logicalConnPoint));
210         }
211         InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(portMap, OtnOdu.class, logicalConnPoint
212                 + "-ODU0-" + serviceName);
213         oduInterfaceBldr.setSupportingInterface(supportingInterface);
214
215         // ODU interface specific data
216         OduBuilder oduIfBuilder = new OduBuilder()
217             .setRate(ODU0.class)
218             .setOduFunction(ODUTTPCTP.class)
219             .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
220         if (isNetworkPort) {
221             List<Integer> tribSlots = new ArrayList<>();
222             tribSlots.add(tribSlot); //add trib slots
223             ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
224                     //set trib port numbers
225                     .setTribPortNumber(tribPortNumber)
226                     .setTribSlots(tribSlots);
227             oduIfBuilder.setOduFunction(ODUCTP.class)
228                     .setMonitoringMode(OduAttributes.MonitoringMode.NotTerminated)
229                     .setParentOduAllocation(parentOduAllocationBuilder.build());
230         }
231         else {
232             // Set Opu attributes
233             OpuBuilder opuBldr = new OpuBuilder()
234                 .setPayloadType(new PayloadTypeDef(payLoad))
235                 .setExpPayloadType(new PayloadTypeDef(payLoad));
236                 //.setRxPayloadType("07")
237                 //.setPayloadInterface(payLoad);
238             oduIfBuilder.setOpu(opuBldr.build());
239         }
240         // Create Interface1 type object required for adding as augmentation
241         // TODO look at imports of different versions of class
242         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder oduIf1Builder =
243             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
244         oduInterfaceBldr.addAugmentation(
245             org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
246             oduIf1Builder.setOdu(oduIfBuilder.build()).build());
247
248         // Post interface on the device
249         this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
250         LOG.info("returning the ODU0 inteface {}", oduInterfaceBldr.getName());
251         return oduInterfaceBldr.getName();
252     }
253
254     public String createOpenRoadmOdu2Interface(String nodeId, String logicalConnPoint, String serviceName,
255             String payLoad, boolean isNetworkPort)
256             throws OpenRoadmInterfaceException {
257         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
258         String supportingInterface = null;
259         if (portMap == null) {
260             throw new OpenRoadmInterfaceException(
261                 String.format("Unable to get mapping from PortMapping for node % and logical connection port %s",
262                     nodeId, logicalConnPoint));
263         }
264         if (isNetworkPort) {
265             supportingInterface = portMap.getSupportingOdu4();
266         } else {
267             supportingInterface = portMap.getSupportingEthernet();
268         }
269         InterfaceBuilder oduInterfaceBldr =
270             createGenericInterfaceBuilder(portMap, OtnOdu.class, logicalConnPoint + "-ODU2-" + serviceName)
271                 .setSupportingInterface(supportingInterface);
272
273         OduBuilder oduIfBuilder = new OduBuilder()
274             .setRate(ODU2.class)
275             .setOduFunction(ODUTTPCTP.class)
276             .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
277         if (isNetworkPort) {
278             List<Integer> tribSlots = new ArrayList<>();
279             tribSlots.add(45); //add trib slots
280             ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
281                     //set trib port numbers
282                     .setTribPortNumber(24)
283                     .setTribSlots(tribSlots);
284             oduIfBuilder.setOduFunction(ODUCTP.class)
285                     .setMonitoringMode(OduAttributes.MonitoringMode.NotTerminated)
286                     .setParentOduAllocation(parentOduAllocationBuilder.build());
287         }
288         else {
289             // Set Opu attributes
290             OpuBuilder opuBldr = new OpuBuilder()
291                 .setPayloadType(new PayloadTypeDef(payLoad))
292                 .setExpPayloadType(new PayloadTypeDef(payLoad));
293                 //.setRxPayloadType("07")
294                 //.setPayloadInterface(payLoad);
295             oduIfBuilder.setOpu(opuBldr.build());
296         }
297
298         // Create Interface1 type object required for adding as augmentation
299         // TODO look at imports of different versions of class
300         // Create Interface1 type object required for adding as augmentation
301         // TODO look at imports of different versions of class
302         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder oduIf1Builder =
303             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
304         oduInterfaceBldr.addAugmentation(
305             org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
306             oduIf1Builder.setOdu(oduIfBuilder.build()).build());
307
308         // Post interface on the device
309         this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
310         LOG.info("returning the ODU2 inteface {}", oduInterfaceBldr.getName());
311         return oduInterfaceBldr.getName();
312     }
313 }