blob: d65a15fad708102a6d4dc58dde61c974ec62d64a [file] [log] [blame]
Praseed Balakrishnane48aa682014-10-08 17:31:37 -07001package org.onlab.onos.openflow.drivers.impl;
2
3import org.onlab.onos.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted;
4import org.onlab.onos.openflow.controller.driver.SwitchDriverSubHandshakeCompleted;
5import org.onlab.onos.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted;
6import org.onlab.onos.openflow.controller.Dpid;
7import org.onlab.onos.openflow.controller.driver.AbstractOpenFlowSwitch;
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -07008import org.projectfloodlight.openflow.protocol.OFBarrierRequest;
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -07009import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus;
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070010import org.projectfloodlight.openflow.protocol.OFCircuitPortsReply;
11import org.projectfloodlight.openflow.protocol.OFCircuitPortsRequest;
12import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
13import org.projectfloodlight.openflow.protocol.OFErrorMsg;
14import org.projectfloodlight.openflow.protocol.OFMatchV3;
15import org.projectfloodlight.openflow.protocol.OFMessage;
16import org.projectfloodlight.openflow.protocol.OFOxmList;
17import org.projectfloodlight.openflow.protocol.OFPortDesc;
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -070018import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply;
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070019import org.projectfloodlight.openflow.protocol.OFPortOptical;
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -070020import org.projectfloodlight.openflow.protocol.OFStatsReply;
21import org.projectfloodlight.openflow.protocol.OFStatsType;
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070022import org.projectfloodlight.openflow.protocol.action.OFAction;
23import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
24import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
25import org.projectfloodlight.openflow.protocol.oxm.OFOxmInPort;
26import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid;
27import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic;
28import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigtype;
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070029import org.projectfloodlight.openflow.types.CircuitSignalID;
30import org.projectfloodlight.openflow.types.OFPort;
31import org.projectfloodlight.openflow.types.U8;
32import org.slf4j.Logger;
33import org.slf4j.LoggerFactory;
34
35import java.io.IOException;
36import java.util.ArrayList;
37import java.util.Collection;
38import java.util.Collections;
39import java.util.List;
40import java.util.concurrent.atomic.AtomicBoolean;
41
42/**
43 * LINC-OE Optical Emulator switch class.
44 */
45public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch {
46
47 private final AtomicBoolean driverHandshakeComplete;
48 private long barrierXidToWaitFor = -1;
49
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -070050 private OFPortDescStatsReply wPorts;
51
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070052 private final Logger log =
53 LoggerFactory.getLogger(OFOpticalSwitchImplLINC13.class);
54
Yuta HIGUCHIbccb6be2014-10-09 17:20:29 -070055 OFOpticalSwitchImplLINC13(Dpid dpid, OFDescStatsReply desc) {
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070056 super(dpid);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070057 driverHandshakeComplete = new AtomicBoolean(false);
58 setSwitchDescription(desc);
59 }
60
61 @Override
62 public String toString() {
63 return "OFOpticalSwitchImplLINC13 [" + ((channel != null)
64 ? channel.getRemoteAddress() : "?")
65 + " DPID[" + ((getStringId() != null) ? getStringId() : "?") + "]]";
66 }
67
68 @Override
69 public void startDriverHandshake() {
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -070070 log.warn("Starting driver handshake for sw {}", getStringId());
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070071 if (startDriverHandshakeCalled) {
72 throw new SwitchDriverSubHandshakeAlreadyStarted();
73 }
74 startDriverHandshakeCalled = true;
75 try {
76 sendHandshakeOFExperimenterPortDescRequest();
77 } catch (IOException e) {
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -070078 log.error("LINC-OE exception while sending experimenter port desc:",
79 e.getMessage());
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070080 e.printStackTrace();
81 }
82 }
83
84 @Override
85 public boolean isDriverHandshakeComplete() {
86 if (!startDriverHandshakeCalled) {
87 throw new SwitchDriverSubHandshakeNotStarted();
88 }
89 return driverHandshakeComplete.get();
90 }
91
92 @Override
93 public void processDriverHandshakeMessage(OFMessage m) {
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -070094 if (!startDriverHandshakeCalled) {
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070095 throw new SwitchDriverSubHandshakeNotStarted();
96 }
97 if (driverHandshakeComplete.get()) {
98 throw new SwitchDriverSubHandshakeCompleted(m);
99 }
100
101 switch (m.getType()) {
102 case BARRIER_REPLY:
103 if (m.getXid() == barrierXidToWaitFor) {
104 log.debug("LINC-OE Received barrier response");
105 }
106 break;
107 case ERROR:
108 log.error("Switch {} Error {}", getStringId(), (OFErrorMsg) m);
109 break;
110 case FEATURES_REPLY:
111 break;
112 case FLOW_REMOVED:
113 break;
114 case GET_ASYNC_REPLY:
115 break;
116 case PACKET_IN:
117 break;
118 case PORT_STATUS:
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700119 log.warn("****LINC-OE Port Status {} {}", getStringId(), m);
120 processOFPortStatus((OFCircuitPortStatus) m);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700121 break;
122 case QUEUE_GET_CONFIG_REPLY:
123 break;
124 case ROLE_REPLY:
125 break;
126 case STATS_REPLY:
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700127 OFStatsReply stats = (OFStatsReply) m;
128 if (stats.getStatsType() == OFStatsType.EXPERIMENTER) {
129 log.warn("LINC-OE : Received stats reply message {}", m);
130 processHandshakeOFExperimenterPortDescRequest(
131 (OFCircuitPortsReply) m);
132 driverHandshakeComplete.set(true);
133 }
134 /*try {
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700135 testMA();
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700136 testReverseMA();
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700137 } catch (IOException e) {
138 e.printStackTrace();
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700139 }*/
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700140 break;
141 default:
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700142 log.warn("Received message {} during switch-driver " +
143 "subhandshake " + "from switch {} ... " +
144 "Ignoring message", m,
145 getStringId());
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700146
147 }
148 }
149
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700150 //Todo
151 public void processOFPortStatus(OFCircuitPortStatus ps) {
152 log.debug("LINC-OE ..OF Port Status :", ps);
153
154 }
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700155
156 private void processHandshakeOFExperimenterPortDescRequest(
157 OFCircuitPortsReply sr) {
158 Collection<OFPortOptical> entries = sr.getEntries();
159 List<OFPortDesc> ofPortDescList = new ArrayList<>(entries.size());
160 for (OFPortOptical entry : entries) {
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700161 log.warn("LINC:OE port message {}", entry.toString());
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700162 ofPortDescList.add(factory().buildPortDesc().
163 setPortNo(entry.getPortNo())
164 .setConfig(entry.getConfig())
165 .setState(entry.getState())
166 .setHwAddr(entry.getHwAddr())
167 .setName(entry.getName())
168 .build());
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700169
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700170 }
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700171 setExperimenterPortDescReply(factory().buildPortDescStatsReply().
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700172 setEntries(ofPortDescList).build());
173 }
174
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700175 private void setExperimenterPortDescReply(OFPortDescStatsReply reply) {
176 wPorts = reply;
177 }
178
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700179
180 private void sendHandshakeOFExperimenterPortDescRequest() throws
181 IOException {
182 // send multi part message for port description for optical switches
183 OFCircuitPortsRequest circuitPortsRequest = factory()
184 .buildCircuitPortsRequest().setXid(getNextTransactionId())
185 .build();
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700186 log.warn("LINC-OE : Sending experimented circuit port stats " +
187 "message " +
188 "{}",
189 circuitPortsRequest.toString());
190 this.write(Collections.<OFMessage>singletonList(circuitPortsRequest));
191 }
192
193
194 @Override
195 public List<OFPortDesc> getPorts() {
196 List<OFPortDesc> portEntries = new ArrayList<>();
197 portEntries.addAll(ports.getEntries());
198 if (wPorts != null) {
199 portEntries.addAll(wPorts.getEntries());
200 }
201 return Collections.unmodifiableList(portEntries);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700202 }
203
204
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700205 public static final U8 SIGNAL_TYPE = U8.of((short) 10);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700206 private void testMA() throws IOException {
207 log.debug("LINC OE *** Testing MA ");
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700208 short lambda = 1;
209 if (getId() == 0x0000ffffffffff01L) {
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700210 final int inport = 10;
211 final int outport = 20;
212 //Circuit signal id
213 CircuitSignalID sigID = getSignalID(lambda);
214
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700215 OFOxmOchSigidBasic ofOxmOchSigidBasic =
216 factory().oxms().ochSigidBasic(sigID);
217
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700218
219 //Match Port
220 OFOxmInPort fieldPort = factory().oxms()
221 .inPort(OFPort.of(inport));
222 OFMatchV3 matchPort =
223 factory()
224 .buildMatchV3().
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700225 setOxmList(OFOxmList.of(fieldPort)).build();
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700226
227
228 // Set Action outport ,sigType and sigID
229 List<OFAction> actionList = new ArrayList<>();
230 OFAction actionOutPort =
231 factory().actions().output(OFPort.of(outport),
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700232 0xffff);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700233
234 OFActionCircuit actionCircuit = factory()
235 .actions()
236 .circuit(ofOxmOchSigidBasic);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700237
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700238 actionList.add(actionCircuit);
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700239 actionList.add(actionOutPort);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700240
241 OFInstruction instructionAction =
242 factory().instructions().buildApplyActions()
243 .setActions(actionList)
244 .build();
245 List<OFInstruction> instructions =
246 Collections.singletonList(instructionAction);
247
248 OFMessage opticalFlowEntry =
249 factory().buildFlowAdd()
250 .setMatch(matchPort)
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700251 .setPriority(100)
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700252 .setInstructions(instructions)
253 .setXid(getNextTransactionId())
254 .build();
255 log.debug("Adding optical flow in sw {}", getStringId());
256 List<OFMessage> msglist = new ArrayList<>(1);
257 msglist.add(opticalFlowEntry);
258 write(msglist);
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700259 sendBarrier(true);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700260 } else if (getId() == 0x0000ffffffffff03L) {
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700261 final int inport = 30;
262 final int outport = 31;
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700263 //Circuit signal id
264 CircuitSignalID sigID = getSignalID(lambda);
265
266 OFOxmOchSigid fieldSigIDMatch = factory().oxms().ochSigid(sigID);
267 OFOxmOchSigtype fieldSigType = factory()
268 .oxms()
269 .ochSigtype(SIGNAL_TYPE);
270
271 OFOxmOchSigidBasic ofOxmOchSigidBasic =
272 factory().oxms().ochSigidBasic(sigID);
273
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700274 //Match Port,SigType,SigID
275 OFOxmInPort fieldPort = factory()
276 .oxms()
277 .inPort(OFPort.of(inport));
278 OFMatchV3 matchPort = factory()
279 .buildMatchV3()
280 .setOxmList(OFOxmList.of(fieldPort,
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700281 fieldSigIDMatch,
282 fieldSigType
283 ))
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700284 .build();
285
286 // Set Action outport ,SigType, sigID
287 List<OFAction> actionList = new ArrayList<>();
288 OFAction actionOutPort =
289 factory().actions().output(OFPort.of(outport),
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700290 0xffff);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700291
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700292 OFActionCircuit actionCircuit = factory()
293 .actions()
294 .circuit(ofOxmOchSigidBasic);
295
296
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700297
298 //actionList.add(setActionSigType);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700299 actionList.add(actionCircuit);
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700300 actionList.add(actionOutPort);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700301
302 OFInstruction instructionAction =
303 factory().instructions().buildApplyActions()
304 .setActions(actionList)
305 .build();
306 List<OFInstruction> instructions =
307 Collections.singletonList(instructionAction);
308
309 OFMessage opticalFlowEntry =
310 factory().buildFlowAdd()
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700311 .setMatch(matchPort)
312 .setPriority(100)
313 .setInstructions(instructions)
314 .setXid(getNextTransactionId())
315 .build();
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700316 log.debug("Adding optical flow in sw {}", getStringId());
317 List<OFMessage> msglist = new ArrayList<>(1);
318 msglist.add(opticalFlowEntry);
319 write(msglist);
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700320 sendBarrier(true);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700321
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700322 } else if (getId() == 0x0000ffffffffff02L) {
323 final int inport = 21;
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700324 final int outport = 11;
325 //Circuit signal id
326 CircuitSignalID sigID = getSignalID(lambda);
327
328 OFOxmOchSigid fieldSigIDMatch = factory().oxms().ochSigid(sigID);
329 OFOxmOchSigtype fieldSigType = factory()
330 .oxms()
331 .ochSigtype(SIGNAL_TYPE);
332
333
334 //Match Port, sig type and sig id
335 OFOxmInPort fieldPort = factory()
336 .oxms()
337 .inPort(OFPort.of(inport));
338 OFMatchV3 matchPort =
339 factory().buildMatchV3()
340 .setOxmList(OFOxmList.of(fieldPort,
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700341 fieldSigIDMatch,
342 fieldSigType
343 ))
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700344 .build();
345
346 // Set Action outport
347 List<OFAction> actionList = new ArrayList<>();
348 OFAction actionOutPort =
349 factory().actions().output(OFPort.of(outport),
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700350 0xffff);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700351
352 actionList.add(actionOutPort);
353
354 OFInstruction instructionAction =
355 factory().instructions().buildApplyActions()
356 .setActions(actionList)
357 .build();
358 List<OFInstruction> instructions =
359 Collections.singletonList(instructionAction);
360
361 OFMessage opticalFlowEntry =
362 factory().buildFlowAdd()
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700363 .setMatch(matchPort)
364 .setPriority(100)
365 .setInstructions(instructions)
366 .setXid(getNextTransactionId())
367 .build();
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700368 log.debug("Adding optical flow in sw {}", getStringId());
369 List<OFMessage> msglist = new ArrayList<>(1);
370 msglist.add(opticalFlowEntry);
371 write(msglist);
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700372 sendBarrier(true);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700373 }
374
375 }
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700376 private void testReverseMA() throws IOException {
377 log.debug("LINC OE *** Testing MA ");
378 short lambda = 1;
379 if (getId() == 0x0000ffffffffff02L) {
380 final int inport = 11;
381 final int outport = 21;
382 //Circuit signal id
383 CircuitSignalID sigID = getSignalID(lambda);
384
385 OFOxmOchSigidBasic ofOxmOchSigidBasic =
386 factory().oxms().ochSigidBasic(sigID);
387
388 //Match Port
389 OFOxmInPort fieldPort = factory().oxms()
390 .inPort(OFPort.of(inport));
391 OFMatchV3 matchPort =
392 factory()
393 .buildMatchV3().
394 setOxmList(OFOxmList.of(fieldPort)).build();
395
396
397 // Set Action outport ,sigType and sigID
398 List<OFAction> actionList = new ArrayList<>();
399 OFAction actionOutPort =
400 factory().actions().output(OFPort.of(outport),
401 0xffff);
402
403 OFActionCircuit actionCircuit = factory()
404 .actions()
405 .circuit(ofOxmOchSigidBasic);
406 actionList.add(actionCircuit);
407 actionList.add(actionOutPort);
408
409 OFInstruction instructionAction =
410 factory().instructions().buildApplyActions()
411 .setActions(actionList)
412 .build();
413 List<OFInstruction> instructions =
414 Collections.singletonList(instructionAction);
415
416 OFMessage opticalFlowEntry =
417 factory().buildFlowAdd()
418 .setMatch(matchPort)
419 .setPriority(100)
420 .setInstructions(instructions)
421 .setXid(getNextTransactionId())
422 .build();
423 log.debug("Adding optical flow in sw {}", getStringId());
424 List<OFMessage> msglist = new ArrayList<>(1);
425 msglist.add(opticalFlowEntry);
426 write(msglist);
427 sendBarrier(true);
428 } else if (getId() == 0x0000ffffffffff03L) {
429 final int inport = 31;
430 final int outport = 30;
431 //Circuit signal id
432 CircuitSignalID sigID = getSignalID(lambda);
433
434 OFOxmOchSigid fieldSigIDMatch = factory().oxms().ochSigid(sigID);
435 OFOxmOchSigtype fieldSigType = factory()
436 .oxms()
437 .ochSigtype(SIGNAL_TYPE);
438
439 OFOxmOchSigidBasic ofOxmOchSigidBasic =
440 factory().oxms().ochSigidBasic(sigID);
441
442 //Match Port,SigType,SigID
443 OFOxmInPort fieldPort = factory()
444 .oxms()
445 .inPort(OFPort.of(inport));
446 OFMatchV3 matchPort = factory()
447 .buildMatchV3()
448 .setOxmList(OFOxmList.of(fieldPort,
449 fieldSigIDMatch,
450 fieldSigType
451 ))
452 .build();
453
454 // Set Action outport ,SigType, sigID
455 List<OFAction> actionList = new ArrayList<>();
456 OFAction actionOutPort =
457 factory().actions().output(OFPort.of(outport),
458 0xffff);
459 OFActionCircuit actionCircuit = factory()
460 .actions()
461 .circuit(ofOxmOchSigidBasic);
462
463 actionList.add(actionCircuit);
464 actionList.add(actionOutPort);
465
466 OFInstruction instructionAction =
467 factory().instructions().buildApplyActions()
468 .setActions(actionList)
469 .build();
470 List<OFInstruction> instructions =
471 Collections.singletonList(instructionAction);
472
473 OFMessage opticalFlowEntry =
474 factory().buildFlowAdd()
475 .setMatch(matchPort)
476 .setPriority(100)
477 .setInstructions(instructions)
478 .setXid(getNextTransactionId())
479 .build();
480 log.debug("Adding optical flow in sw {}", getStringId());
481 List<OFMessage> msglist = new ArrayList<>(1);
482 msglist.add(opticalFlowEntry);
483 write(msglist);
484 sendBarrier(true);
485
486 } else if (getId() == 0x0000ffffffffff01L) {
487 final int inport = 20;
488 final int outport = 10;
489 //Circuit signal id
490 CircuitSignalID sigID = getSignalID(lambda);
491
492 OFOxmOchSigid fieldSigIDMatch = factory().oxms().ochSigid(sigID);
493 OFOxmOchSigtype fieldSigType = factory()
494 .oxms()
495 .ochSigtype(SIGNAL_TYPE);
496
497
498 //Match Port, sig type and sig id
499 OFOxmInPort fieldPort = factory()
500 .oxms()
501 .inPort(OFPort.of(inport));
502 OFMatchV3 matchPort =
503 factory().buildMatchV3()
504 .setOxmList(OFOxmList.of(fieldPort,
505 fieldSigIDMatch,
506 fieldSigType
507 ))
508 .build();
509
510 // Set Action outport
511 List<OFAction> actionList = new ArrayList<>();
512 OFAction actionOutPort =
513 factory().actions().output(OFPort.of(outport),
514 0xffff);
515
516 actionList.add(actionOutPort);
517
518 OFInstruction instructionAction =
519 factory().instructions().buildApplyActions()
520 .setActions(actionList)
521 .build();
522 List<OFInstruction> instructions =
523 Collections.singletonList(instructionAction);
524
525 OFMessage opticalFlowEntry =
526 factory().buildFlowAdd()
527 .setMatch(matchPort)
528 .setPriority(100)
529 .setInstructions(instructions)
530 .setXid(getNextTransactionId())
531 .build();
532 log.debug("Adding optical flow in sw {}", getStringId());
533 List<OFMessage> msglist = new ArrayList<>(1);
534 msglist.add(opticalFlowEntry);
535 write(msglist);
536 sendBarrier(true);
537 }
538
539 }
540
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700541
542 // Todo remove - for testing purpose only
543 private static CircuitSignalID getSignalID(short lambda) {
544 byte myGrid = 1;
545 byte myCs = 2;
546 short myCn = lambda;
547 short mySw = 1;
548
549 CircuitSignalID signalID = new CircuitSignalID(myGrid,
550 myCs,
551 myCn,
552 mySw);
553 return signalID;
554 }
555
Praseed Balakrishnan610c1e12014-10-15 16:34:59 -0700556 private void sendBarrier(boolean finalBarrier) throws IOException {
557 int xid = getNextTransactionId();
558 if (finalBarrier) {
559 barrierXidToWaitFor = xid;
560 }
561 OFBarrierRequest br = factory()
562 .buildBarrierRequest()
563 .setXid(xid)
564 .build();
565 sendMsg(br);
566 }
567
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700568 @Override
569 public void write(OFMessage msg) {
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700570 this.channel.write(Collections.singletonList(msg));
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700571 }
572
573 @Override
574 public void write(List<OFMessage> msgs) {
575 this.channel.write(msgs);
576 }
577
578 @Override
579 public Boolean supportNxRole() {
580 return false;
581 }
582
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700583 @Override
584 public boolean isOptical() {
585 return true;
586 }
587
588
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700589}