blob: fe26d72d5c35184e8d3eadb2ddcfce0f66f17787 [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
79 // Proper cross connect has criteria for input port, OChSignal and OCh signal type.
80 // Instruction is only output to port (rule generated by ROADM app).
81 // Instruction includes output port and OChSignal (rule generated by OpticalConnectivityIntent).
82 checkArgument((criteria.size() == NUM_CRITERIA_INTENT) ||
83 (criteria.size() == NUM_CRITERIA_ROADM),
84 "Wrong size of flow rule criteria for cross connect.");
85 checkArgument((instructions.size() == NUM_INSTRUCTIONS_INTENT) ||
86 (instructions.size() == NUM_INSTRUCTIONS_ROADM),
87 "Wrong size of flow rule instructions for cross connect.");
88
89 // FIXME: Ensure criteria has exactly one of each match type
90 criteria.forEach(
91 c -> checkArgument(c instanceof OchSignalCriterion ||
92 c instanceof OchSignalTypeCriterion ||
93 c instanceof PortCriterion,
94 "Incompatible flow rule criteria for LumentumROADM: " + criteria
95 )
96 );
97
98 instructions.forEach(
99 c -> checkArgument(c instanceof Instructions.OutputInstruction ||
100 c instanceof L0ModificationInstruction,
101 "Incompatible flow rule instruction for LumentumROADM: " + instructions
102 )
103 );
104
105 if (criteria.size() == NUM_CRITERIA_INTENT && instructions.size() == NUM_INSTRUCTIONS_INTENT) {
106 log.info("Lumentum device, FlowRule coming from OpticalConnectivityIntentCompiler");
107
108 type = Type.OPTICAL_CONNECTIVITY_INTENT_RULE;
109 } else {
110 log.info("Lumentum device, FlowRule coming from ROADM app");
111
112 type = Type.ROADM_APP_RULE;
113 }
114
115 ochSignal = criteria.stream()
116 .filter(c -> c instanceof OchSignalCriterion)
117 .map(c -> ((OchSignalCriterion) c).lambda())
118 .findAny()
119 .orElse(null);
120
121 inputPort = criteria.stream()
122 .filter(c -> c instanceof PortCriterion)
123 .map(c -> ((PortCriterion) c).port())
124 .findAny()
125 .orElse(null);
126
127 outputPort = instructions.stream()
128 .filter(c -> c instanceof Instructions.OutputInstruction)
129 .map(c -> ((Instructions.OutputInstruction) c).port())
130 .findAny()
131 .orElse(null);
132
133 // Add or drop rule? Get the output instruction
134 Instructions.OutputInstruction outInstruction = (Instructions.OutputInstruction) instructions.stream()
135 .filter(c -> c instanceof Instructions.OutputInstruction)
136 .findAny()
137 .orElse(null);
138
139 if (linePorts.contains(outInstruction.port())) {
140 addDrop = criteria.stream()
141 .filter(c -> c instanceof PortCriterion)
142 .map(c -> ((PortCriterion) c).port())
143 .findAny()
144 .orElse(null);
145 isAddRule = true;
146 } else {
147 addDrop = outInstruction.port();
148 isAddRule = false;
149 }
alessio1bf2a632019-06-04 15:47:39 +0200150
151 connectionName = "inPort" + inputPort.toString() + "-ochSig-" + ochSignal.centralFrequency().toString();
alessiod4a2b842019-04-30 18:43:17 +0200152 }
153
154 public PortNumber addDrop() {
155 return addDrop;
156 }
157
158 public OchSignal ochSignal() {
159 return ochSignal;
160 }
161
162 public boolean isAddRule() {
163 return isAddRule;
164 }
165
166 public PortNumber getInputPort() {
167 return inputPort;
168 }
169
170 public PortNumber getOutputPort() {
171 return outputPort;
172 }
alessio1bf2a632019-06-04 15:47:39 +0200173
174 public String getConnectionName() {
175 return connectionName;
176 }
177
178 public int getConnectionId() {
179 return connectionId;
180 }
181
182 public int getConnectionModule() {
183 return connectionModule;
184 }
185
186 public void setConnectionId(int id) {
187 connectionId = id;
188 }
189
190 public void setConnectionModule(int id) {
191 connectionModule = id;
192 }
193
194 protected void setAttenuation(double att) {
195 attenuation = att;
196 }
197
198 protected void setInputPower(double power) {
199 inputPower = power;
200 }
201
202 protected void setOutputPower(double power) {
203 outputPower = power;
204 }
alessiod4a2b842019-04-30 18:43:17 +0200205}