blob: 1d29f13f2865aad1b67730809a622477f1af9b60 [file] [log] [blame]
alessiod4a2b842019-04-30 18:43:17 +02001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.drivers.lumentum;
18
19import org.onosproject.net.OchSignal;
20import org.onosproject.net.PortNumber;
21import org.onosproject.net.flow.DefaultFlowRule;
22import org.onosproject.net.flow.FlowRule;
23import org.onosproject.net.flow.criteria.Criterion;
24import org.onosproject.net.flow.criteria.OchSignalCriterion;
25import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
26import org.onosproject.net.flow.criteria.PortCriterion;
27import org.onosproject.net.flow.instructions.Instruction;
28import org.onosproject.net.flow.instructions.Instructions;
29import org.onosproject.net.flow.instructions.L0ModificationInstruction;
30import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
33import java.util.List;
34import java.util.Set;
35
36import static com.google.common.base.Preconditions.checkArgument;
37
38public class LumentumFlowRule extends DefaultFlowRule {
39 private static final Logger log = LoggerFactory.getLogger(LumentumFlowRule.class);
40
41 protected enum Type {
42 OPTICAL_CONNECTIVITY_INTENT_RULE,
43 ROADM_APP_RULE
44 }
45 public Type type;
46
alessio1bf2a632019-06-04 15:47:39 +020047 private String connectionName;
48 private int connectionId;
49 private int connectionModule;
alessiod4a2b842019-04-30 18:43:17 +020050 private PortNumber addDrop;
51
52 private PortNumber inputPort;
53 private PortNumber outputPort;
54
55 private OchSignal ochSignal;
56 private boolean isAddRule;
57
alessio1bf2a632019-06-04 15:47:39 +020058 protected double attenuation;
59 protected double targetAttenuation;
60 protected double targetPower;
61 protected double inputPower;
62 protected double outputPower;
63
alessiod4a2b842019-04-30 18:43:17 +020064 //As generated by the OpticalConnectivityIntentCompiler
65 private static final int NUM_CRITERIA_INTENT = 3;
66 private static final int NUM_INSTRUCTIONS_INTENT = 2;
67
68 //As generated dy ROADM app
69 private static final int NUM_CRITERIA_ROADM = 3;
70 private static final int NUM_INSTRUCTIONS_ROADM = 1;
71
alessio1bf2a632019-06-04 15:47:39 +020072
alessiod4a2b842019-04-30 18:43:17 +020073 public LumentumFlowRule(FlowRule rule, List<PortNumber> linePorts) {
74 super(rule);
75
76 Set<Criterion> criteria = rule.selector().criteria();
77 List<Instruction> instructions = rule.treatment().immediate();
78
alessioa9bcacc2021-09-24 17:32:57 +020079 log.debug("Lumentum device received criteria {} - treatment {}",
80 criteria,
81 instructions);
82
alessiod4a2b842019-04-30 18:43:17 +020083 // Proper cross connect has criteria for input port, OChSignal and OCh signal type.
84 // Instruction is only output to port (rule generated by ROADM app).
85 // Instruction includes output port and OChSignal (rule generated by OpticalConnectivityIntent).
86 checkArgument((criteria.size() == NUM_CRITERIA_INTENT) ||
87 (criteria.size() == NUM_CRITERIA_ROADM),
88 "Wrong size of flow rule criteria for cross connect.");
89 checkArgument((instructions.size() == NUM_INSTRUCTIONS_INTENT) ||
90 (instructions.size() == NUM_INSTRUCTIONS_ROADM),
91 "Wrong size of flow rule instructions for cross connect.");
92
93 // FIXME: Ensure criteria has exactly one of each match type
94 criteria.forEach(
95 c -> checkArgument(c instanceof OchSignalCriterion ||
96 c instanceof OchSignalTypeCriterion ||
97 c instanceof PortCriterion,
98 "Incompatible flow rule criteria for LumentumROADM: " + criteria
99 )
100 );
101
102 instructions.forEach(
103 c -> checkArgument(c instanceof Instructions.OutputInstruction ||
104 c instanceof L0ModificationInstruction,
105 "Incompatible flow rule instruction for LumentumROADM: " + instructions
106 )
107 );
108
109 if (criteria.size() == NUM_CRITERIA_INTENT && instructions.size() == NUM_INSTRUCTIONS_INTENT) {
alessioa9bcacc2021-09-24 17:32:57 +0200110 log.debug("Lumentum device, FlowRule coming from OpticalConnectivityIntentCompiler");
alessiod4a2b842019-04-30 18:43:17 +0200111
112 type = Type.OPTICAL_CONNECTIVITY_INTENT_RULE;
113 } else {
alessioa9bcacc2021-09-24 17:32:57 +0200114 log.debug("Lumentum device, FlowRule coming from ROADM app");
alessiod4a2b842019-04-30 18:43:17 +0200115
116 type = Type.ROADM_APP_RULE;
117 }
118
119 ochSignal = criteria.stream()
120 .filter(c -> c instanceof OchSignalCriterion)
121 .map(c -> ((OchSignalCriterion) c).lambda())
122 .findAny()
123 .orElse(null);
124
alessioa9bcacc2021-09-24 17:32:57 +0200125 checkArgument(ochSignal.slotGranularity() == 4 || ochSignal.slotGranularity() == 8,
126 "Lumentum device, only supports 50 GHz and 100 GHz frequency slots");
127
alessiod4a2b842019-04-30 18:43:17 +0200128 inputPort = criteria.stream()
129 .filter(c -> c instanceof PortCriterion)
130 .map(c -> ((PortCriterion) c).port())
131 .findAny()
132 .orElse(null);
133
134 outputPort = instructions.stream()
135 .filter(c -> c instanceof Instructions.OutputInstruction)
136 .map(c -> ((Instructions.OutputInstruction) c).port())
137 .findAny()
138 .orElse(null);
139
140 // Add or drop rule? Get the output instruction
141 Instructions.OutputInstruction outInstruction = (Instructions.OutputInstruction) instructions.stream()
142 .filter(c -> c instanceof Instructions.OutputInstruction)
143 .findAny()
144 .orElse(null);
145
146 if (linePorts.contains(outInstruction.port())) {
147 addDrop = criteria.stream()
148 .filter(c -> c instanceof PortCriterion)
149 .map(c -> ((PortCriterion) c).port())
150 .findAny()
151 .orElse(null);
152 isAddRule = true;
153 } else {
154 addDrop = outInstruction.port();
155 isAddRule = false;
156 }
alessio1bf2a632019-06-04 15:47:39 +0200157
158 connectionName = "inPort" + inputPort.toString() + "-ochSig-" + ochSignal.centralFrequency().toString();
alessiod4a2b842019-04-30 18:43:17 +0200159 }
160
161 public PortNumber addDrop() {
162 return addDrop;
163 }
164
165 public OchSignal ochSignal() {
166 return ochSignal;
167 }
168
169 public boolean isAddRule() {
170 return isAddRule;
171 }
172
173 public PortNumber getInputPort() {
174 return inputPort;
175 }
176
177 public PortNumber getOutputPort() {
178 return outputPort;
179 }
alessio1bf2a632019-06-04 15:47:39 +0200180
181 public String getConnectionName() {
182 return connectionName;
183 }
184
185 public int getConnectionId() {
186 return connectionId;
187 }
188
189 public int getConnectionModule() {
190 return connectionModule;
191 }
192
193 public void setConnectionId(int id) {
194 connectionId = id;
195 }
196
197 public void setConnectionModule(int id) {
198 connectionModule = id;
199 }
200
201 protected void setAttenuation(double att) {
202 attenuation = att;
203 }
204
205 protected void setInputPower(double power) {
206 inputPower = power;
207 }
208
209 protected void setOutputPower(double power) {
210 outputPower = power;
211 }
alessiod4a2b842019-04-30 18:43:17 +0200212}