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