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.rev210927.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 + "-ETHERNET100G");
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 serviceName, String payLoad,
92 boolean isNetworkPort, OpucnTribSlotDef minTribSlotNumber, OpucnTribSlotDef maxTribSlotNumber)
93 throws OpenRoadmInterfaceException {
94 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
95 if (portMap == null) {
96 throwException(nodeId, logicalConnPoint);
98 List<String> supportingInterfaceList = new ArrayList<>();
99 String supportingInterface = null;
101 supportingInterface = portMap.getSupportingOduc4();
103 supportingInterface = logicalConnPoint + "-ETHERNET100G";
106 if (supportingInterface == null) {
107 throw new OpenRoadmInterfaceException(
108 "Interface Creation failed because of missing supported "
109 + "ODU4 on network end or Ethernet on client");
111 // Supporting interface is a list for B100G (7.1) device models
112 supportingInterfaceList.add(supportingInterface);
114 InterfaceBuilder oduIfBuilder = createGenericInterfaceBuilder(
115 portMap, OtnOdu.class, logicalConnPoint + "-ODU4-" + serviceName)
116 .setSupportingInterfaceList(supportingInterfaceList);
117 // Agument ODU4 specific interface data
118 OduBuilder oduBuilder = new OduBuilder().setRate(ODU4.class)
119 .setOduFunction(ODUTTPCTP.class)
120 .setMonitoringMode(MonitoringMode.Terminated);
121 LOG.debug("Inside the ODU4 creation {} {} {}", isNetworkPort, minTribSlotNumber.getValue(),
122 maxTribSlotNumber.getValue());
123 // If it is a network port we have fill the required trib-slots and trib-ports
125 List<OpucnTribSlotDef> opucnTribSlotDefList = new ArrayList<>();
126 // Escape characters are used to here to take the literal dot
127 Uint16 tribPortNumber = Uint16.valueOf(minTribSlotNumber.getValue().split("\\.")[0]);
128 Uint16 startTribSlot = Uint16.valueOf(minTribSlotNumber.getValue().split("\\.")[1]);
129 Uint16 endTribSlot = Uint16.valueOf(maxTribSlotNumber.getValue().split("\\.")[1]);
131 IntStream.range(startTribSlot.intValue(), endTribSlot.intValue() + 1)
133 nbr -> opucnTribSlotDefList.add(OpucnTribSlotDef.getDefaultInstance(tribPortNumber + "." + nbr))
135 ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
136 .setTribPortNumber(tribPortNumber)
137 .setTribSlotsChoice(new OpucnBuilder().setOpucnTribSlots(opucnTribSlotDefList).build());
138 // reset the ODU function as ODUCTP and the monitoring moode
139 oduBuilder.setOduFunction(ODUCTP.class)
140 .setMonitoringMode(MonitoringMode.NotTerminated)
141 .setParentOduAllocation(parentOduAllocationBuilder.build());
144 // This is for the client side of the ODU (ODU-TTP-CTP)
145 // Set Opu attributes
146 OpuBuilder opuBuilder = new OpuBuilder()
147 .setExpPayloadType(new PayloadTypeDef(payLoad))
148 .setPayloadType(new PayloadTypeDef(payLoad));
149 oduBuilder.setOpu(opuBuilder.build());
152 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder
154 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
155 oduIfBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
156 // Post interface on the device
157 this.openRoadmInterfaces.postOTNInterface(nodeId, oduIfBuilder);
158 LOG.info("Returning the ODU4 inteface {}", oduIfBuilder.getName());
159 return oduIfBuilder.getName();
162 private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap,
163 Class<? extends InterfaceType> type, String key) {
164 return new InterfaceBuilder()
165 // .setDescription(" TBD ")
166 // .setCircuitId(" TBD ")
167 .setSupportingCircuitPackName(
168 portMap.getSupportingCircuitPackName())
169 .setSupportingPort(portMap.getSupportingPort())
170 .setAdministrativeState(AdminStates.InService)
171 // TODO get rid of unchecked cast warning
172 .setType(type).setName(key).withKey(new InterfaceKey(key));