Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 1 | package org.onlab.onos.openflow.drivers.impl; |
| 2 | |
| 3 | import org.onlab.onos.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted; |
| 4 | import org.onlab.onos.openflow.controller.driver.SwitchDriverSubHandshakeCompleted; |
| 5 | import org.onlab.onos.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted; |
| 6 | import org.onlab.onos.openflow.controller.Dpid; |
| 7 | import org.onlab.onos.openflow.controller.driver.AbstractOpenFlowSwitch; |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 8 | import org.projectfloodlight.openflow.protocol.OFBarrierRequest; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 9 | import org.projectfloodlight.openflow.protocol.OFCircuitPortsReply; |
| 10 | import org.projectfloodlight.openflow.protocol.OFCircuitPortsRequest; |
| 11 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| 12 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
| 13 | import org.projectfloodlight.openflow.protocol.OFMatchV3; |
| 14 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 15 | import org.projectfloodlight.openflow.protocol.OFOxmList; |
| 16 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 17 | import org.projectfloodlight.openflow.protocol.OFPortOptical; |
| 18 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
| 19 | import org.projectfloodlight.openflow.protocol.action.OFActionCircuit; |
| 20 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
| 21 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmInPort; |
| 22 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid; |
| 23 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic; |
| 24 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigtype; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 25 | import org.projectfloodlight.openflow.types.CircuitSignalID; |
| 26 | import org.projectfloodlight.openflow.types.OFPort; |
| 27 | import org.projectfloodlight.openflow.types.U8; |
| 28 | import org.slf4j.Logger; |
| 29 | import org.slf4j.LoggerFactory; |
| 30 | |
| 31 | import java.io.IOException; |
| 32 | import java.util.ArrayList; |
| 33 | import java.util.Collection; |
| 34 | import java.util.Collections; |
| 35 | import java.util.List; |
| 36 | import java.util.concurrent.atomic.AtomicBoolean; |
| 37 | |
| 38 | /** |
| 39 | * LINC-OE Optical Emulator switch class. |
| 40 | */ |
| 41 | public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch { |
| 42 | |
| 43 | private final AtomicBoolean driverHandshakeComplete; |
| 44 | private long barrierXidToWaitFor = -1; |
| 45 | |
| 46 | private final Logger log = |
| 47 | LoggerFactory.getLogger(OFOpticalSwitchImplLINC13.class); |
| 48 | |
Yuta HIGUCHI | bccb6be | 2014-10-09 17:20:29 -0700 | [diff] [blame] | 49 | OFOpticalSwitchImplLINC13(Dpid dpid, OFDescStatsReply desc) { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 50 | super(dpid); |
| 51 | //setAttribute("optical", "true"); |
| 52 | driverHandshakeComplete = new AtomicBoolean(false); |
| 53 | setSwitchDescription(desc); |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public String toString() { |
| 58 | return "OFOpticalSwitchImplLINC13 [" + ((channel != null) |
| 59 | ? channel.getRemoteAddress() : "?") |
| 60 | + " DPID[" + ((getStringId() != null) ? getStringId() : "?") + "]]"; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public void startDriverHandshake() { |
| 65 | log.debug("Starting driver handshake for sw {}", getStringId()); |
| 66 | if (startDriverHandshakeCalled) { |
| 67 | throw new SwitchDriverSubHandshakeAlreadyStarted(); |
| 68 | } |
| 69 | startDriverHandshakeCalled = true; |
| 70 | try { |
| 71 | sendHandshakeOFExperimenterPortDescRequest(); |
| 72 | } catch (IOException e) { |
| 73 | e.printStackTrace(); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public boolean isDriverHandshakeComplete() { |
| 79 | if (!startDriverHandshakeCalled) { |
| 80 | throw new SwitchDriverSubHandshakeNotStarted(); |
| 81 | } |
| 82 | return driverHandshakeComplete.get(); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public void processDriverHandshakeMessage(OFMessage m) { |
| 87 | if (!startDriverHandshakeCalled) { |
| 88 | throw new SwitchDriverSubHandshakeNotStarted(); |
| 89 | } |
| 90 | if (driverHandshakeComplete.get()) { |
| 91 | throw new SwitchDriverSubHandshakeCompleted(m); |
| 92 | } |
| 93 | |
| 94 | switch (m.getType()) { |
| 95 | case BARRIER_REPLY: |
| 96 | if (m.getXid() == barrierXidToWaitFor) { |
| 97 | log.debug("LINC-OE Received barrier response"); |
| 98 | } |
| 99 | break; |
| 100 | case ERROR: |
| 101 | log.error("Switch {} Error {}", getStringId(), (OFErrorMsg) m); |
| 102 | break; |
| 103 | case FEATURES_REPLY: |
| 104 | break; |
| 105 | case FLOW_REMOVED: |
| 106 | break; |
| 107 | case GET_ASYNC_REPLY: |
| 108 | break; |
| 109 | case PACKET_IN: |
| 110 | break; |
| 111 | case PORT_STATUS: |
| 112 | break; |
| 113 | case QUEUE_GET_CONFIG_REPLY: |
| 114 | break; |
| 115 | case ROLE_REPLY: |
| 116 | break; |
| 117 | case STATS_REPLY: |
| 118 | log.debug("LINC-OE : Received stats reply message {}", m); |
| 119 | processHandshakeOFExperimenterPortDescRequest( |
| 120 | (OFCircuitPortsReply) m); |
| 121 | driverHandshakeComplete.set(true); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 122 | try { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 123 | testMA(); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 124 | testReverseMA(); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 125 | } catch (IOException e) { |
| 126 | e.printStackTrace(); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 127 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 128 | break; |
| 129 | default: |
| 130 | log.debug("Received message {} during switch-driver " + |
| 131 | "subhandshake " + "from switch {} ... " + |
| 132 | "Ignoring message", m, |
| 133 | getStringId()); |
| 134 | |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | |
| 139 | private void processHandshakeOFExperimenterPortDescRequest( |
| 140 | OFCircuitPortsReply sr) { |
| 141 | Collection<OFPortOptical> entries = sr.getEntries(); |
| 142 | List<OFPortDesc> ofPortDescList = new ArrayList<>(entries.size()); |
| 143 | for (OFPortOptical entry : entries) { |
| 144 | ofPortDescList.add(factory().buildPortDesc(). |
| 145 | setPortNo(entry.getPortNo()) |
| 146 | .setConfig(entry.getConfig()) |
| 147 | .setState(entry.getState()) |
| 148 | .setHwAddr(entry.getHwAddr()) |
| 149 | .setName(entry.getName()) |
| 150 | .build()); |
| 151 | } |
| 152 | setPortDescReply(factory().buildPortDescStatsReply(). |
| 153 | setEntries(ofPortDescList).build()); |
| 154 | } |
| 155 | |
| 156 | |
| 157 | private void sendHandshakeOFExperimenterPortDescRequest() throws |
| 158 | IOException { |
| 159 | // send multi part message for port description for optical switches |
| 160 | OFCircuitPortsRequest circuitPortsRequest = factory() |
| 161 | .buildCircuitPortsRequest().setXid(getNextTransactionId()) |
| 162 | .build(); |
| 163 | log.debug("LINC-OE : Sending experimented circuit port stats " + |
| 164 | "message " + |
| 165 | "{}", |
| 166 | circuitPortsRequest.toString()); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 167 | sendMsg(Collections.<OFMessage>singletonList(circuitPortsRequest)); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 171 | public static final U8 SIGNAL_TYPE = U8.of((short) 10); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 172 | private void testMA() throws IOException { |
| 173 | log.debug("LINC OE *** Testing MA "); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 174 | short lambda = 1; |
| 175 | if (getId() == 0x0000ffffffffff01L) { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 176 | final int inport = 10; |
| 177 | final int outport = 20; |
| 178 | //Circuit signal id |
| 179 | CircuitSignalID sigID = getSignalID(lambda); |
| 180 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 181 | OFOxmOchSigidBasic ofOxmOchSigidBasic = |
| 182 | factory().oxms().ochSigidBasic(sigID); |
| 183 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 184 | |
| 185 | //Match Port |
| 186 | OFOxmInPort fieldPort = factory().oxms() |
| 187 | .inPort(OFPort.of(inport)); |
| 188 | OFMatchV3 matchPort = |
| 189 | factory() |
| 190 | .buildMatchV3(). |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 191 | setOxmList(OFOxmList.of(fieldPort)).build(); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 192 | |
| 193 | |
| 194 | // Set Action outport ,sigType and sigID |
| 195 | List<OFAction> actionList = new ArrayList<>(); |
| 196 | OFAction actionOutPort = |
| 197 | factory().actions().output(OFPort.of(outport), |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 198 | 0xffff); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 199 | |
| 200 | OFActionCircuit actionCircuit = factory() |
| 201 | .actions() |
| 202 | .circuit(ofOxmOchSigidBasic); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 203 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 204 | actionList.add(actionCircuit); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 205 | actionList.add(actionOutPort); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 206 | |
| 207 | OFInstruction instructionAction = |
| 208 | factory().instructions().buildApplyActions() |
| 209 | .setActions(actionList) |
| 210 | .build(); |
| 211 | List<OFInstruction> instructions = |
| 212 | Collections.singletonList(instructionAction); |
| 213 | |
| 214 | OFMessage opticalFlowEntry = |
| 215 | factory().buildFlowAdd() |
| 216 | .setMatch(matchPort) |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 217 | .setPriority(100) |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 218 | .setInstructions(instructions) |
| 219 | .setXid(getNextTransactionId()) |
| 220 | .build(); |
| 221 | log.debug("Adding optical flow in sw {}", getStringId()); |
| 222 | List<OFMessage> msglist = new ArrayList<>(1); |
| 223 | msglist.add(opticalFlowEntry); |
| 224 | write(msglist); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 225 | sendBarrier(true); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 226 | } else if (getId() == 0x0000ffffffffff03L) { |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 227 | final int inport = 30; |
| 228 | final int outport = 31; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 229 | //Circuit signal id |
| 230 | CircuitSignalID sigID = getSignalID(lambda); |
| 231 | |
| 232 | OFOxmOchSigid fieldSigIDMatch = factory().oxms().ochSigid(sigID); |
| 233 | OFOxmOchSigtype fieldSigType = factory() |
| 234 | .oxms() |
| 235 | .ochSigtype(SIGNAL_TYPE); |
| 236 | |
| 237 | OFOxmOchSigidBasic ofOxmOchSigidBasic = |
| 238 | factory().oxms().ochSigidBasic(sigID); |
| 239 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 240 | //Match Port,SigType,SigID |
| 241 | OFOxmInPort fieldPort = factory() |
| 242 | .oxms() |
| 243 | .inPort(OFPort.of(inport)); |
| 244 | OFMatchV3 matchPort = factory() |
| 245 | .buildMatchV3() |
| 246 | .setOxmList(OFOxmList.of(fieldPort, |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 247 | fieldSigIDMatch, |
| 248 | fieldSigType |
| 249 | )) |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 250 | .build(); |
| 251 | |
| 252 | // Set Action outport ,SigType, sigID |
| 253 | List<OFAction> actionList = new ArrayList<>(); |
| 254 | OFAction actionOutPort = |
| 255 | factory().actions().output(OFPort.of(outport), |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 256 | 0xffff); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 257 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 258 | OFActionCircuit actionCircuit = factory() |
| 259 | .actions() |
| 260 | .circuit(ofOxmOchSigidBasic); |
| 261 | |
| 262 | |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 263 | |
| 264 | //actionList.add(setActionSigType); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 265 | actionList.add(actionCircuit); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 266 | actionList.add(actionOutPort); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 267 | |
| 268 | OFInstruction instructionAction = |
| 269 | factory().instructions().buildApplyActions() |
| 270 | .setActions(actionList) |
| 271 | .build(); |
| 272 | List<OFInstruction> instructions = |
| 273 | Collections.singletonList(instructionAction); |
| 274 | |
| 275 | OFMessage opticalFlowEntry = |
| 276 | factory().buildFlowAdd() |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 277 | .setMatch(matchPort) |
| 278 | .setPriority(100) |
| 279 | .setInstructions(instructions) |
| 280 | .setXid(getNextTransactionId()) |
| 281 | .build(); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 282 | log.debug("Adding optical flow in sw {}", getStringId()); |
| 283 | List<OFMessage> msglist = new ArrayList<>(1); |
| 284 | msglist.add(opticalFlowEntry); |
| 285 | write(msglist); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 286 | sendBarrier(true); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 287 | |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 288 | } else if (getId() == 0x0000ffffffffff02L) { |
| 289 | final int inport = 21; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 290 | final int outport = 11; |
| 291 | //Circuit signal id |
| 292 | CircuitSignalID sigID = getSignalID(lambda); |
| 293 | |
| 294 | OFOxmOchSigid fieldSigIDMatch = factory().oxms().ochSigid(sigID); |
| 295 | OFOxmOchSigtype fieldSigType = factory() |
| 296 | .oxms() |
| 297 | .ochSigtype(SIGNAL_TYPE); |
| 298 | |
| 299 | |
| 300 | //Match Port, sig type and sig id |
| 301 | OFOxmInPort fieldPort = factory() |
| 302 | .oxms() |
| 303 | .inPort(OFPort.of(inport)); |
| 304 | OFMatchV3 matchPort = |
| 305 | factory().buildMatchV3() |
| 306 | .setOxmList(OFOxmList.of(fieldPort, |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 307 | fieldSigIDMatch, |
| 308 | fieldSigType |
| 309 | )) |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 310 | .build(); |
| 311 | |
| 312 | // Set Action outport |
| 313 | List<OFAction> actionList = new ArrayList<>(); |
| 314 | OFAction actionOutPort = |
| 315 | factory().actions().output(OFPort.of(outport), |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 316 | 0xffff); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 317 | |
| 318 | actionList.add(actionOutPort); |
| 319 | |
| 320 | OFInstruction instructionAction = |
| 321 | factory().instructions().buildApplyActions() |
| 322 | .setActions(actionList) |
| 323 | .build(); |
| 324 | List<OFInstruction> instructions = |
| 325 | Collections.singletonList(instructionAction); |
| 326 | |
| 327 | OFMessage opticalFlowEntry = |
| 328 | factory().buildFlowAdd() |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 329 | .setMatch(matchPort) |
| 330 | .setPriority(100) |
| 331 | .setInstructions(instructions) |
| 332 | .setXid(getNextTransactionId()) |
| 333 | .build(); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 334 | log.debug("Adding optical flow in sw {}", getStringId()); |
| 335 | List<OFMessage> msglist = new ArrayList<>(1); |
| 336 | msglist.add(opticalFlowEntry); |
| 337 | write(msglist); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 338 | sendBarrier(true); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | } |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 342 | private void testReverseMA() throws IOException { |
| 343 | log.debug("LINC OE *** Testing MA "); |
| 344 | short lambda = 1; |
| 345 | if (getId() == 0x0000ffffffffff02L) { |
| 346 | final int inport = 11; |
| 347 | final int outport = 21; |
| 348 | //Circuit signal id |
| 349 | CircuitSignalID sigID = getSignalID(lambda); |
| 350 | |
| 351 | OFOxmOchSigidBasic ofOxmOchSigidBasic = |
| 352 | factory().oxms().ochSigidBasic(sigID); |
| 353 | |
| 354 | //Match Port |
| 355 | OFOxmInPort fieldPort = factory().oxms() |
| 356 | .inPort(OFPort.of(inport)); |
| 357 | OFMatchV3 matchPort = |
| 358 | factory() |
| 359 | .buildMatchV3(). |
| 360 | setOxmList(OFOxmList.of(fieldPort)).build(); |
| 361 | |
| 362 | |
| 363 | // Set Action outport ,sigType and sigID |
| 364 | List<OFAction> actionList = new ArrayList<>(); |
| 365 | OFAction actionOutPort = |
| 366 | factory().actions().output(OFPort.of(outport), |
| 367 | 0xffff); |
| 368 | |
| 369 | OFActionCircuit actionCircuit = factory() |
| 370 | .actions() |
| 371 | .circuit(ofOxmOchSigidBasic); |
| 372 | actionList.add(actionCircuit); |
| 373 | actionList.add(actionOutPort); |
| 374 | |
| 375 | OFInstruction instructionAction = |
| 376 | factory().instructions().buildApplyActions() |
| 377 | .setActions(actionList) |
| 378 | .build(); |
| 379 | List<OFInstruction> instructions = |
| 380 | Collections.singletonList(instructionAction); |
| 381 | |
| 382 | OFMessage opticalFlowEntry = |
| 383 | factory().buildFlowAdd() |
| 384 | .setMatch(matchPort) |
| 385 | .setPriority(100) |
| 386 | .setInstructions(instructions) |
| 387 | .setXid(getNextTransactionId()) |
| 388 | .build(); |
| 389 | log.debug("Adding optical flow in sw {}", getStringId()); |
| 390 | List<OFMessage> msglist = new ArrayList<>(1); |
| 391 | msglist.add(opticalFlowEntry); |
| 392 | write(msglist); |
| 393 | sendBarrier(true); |
| 394 | } else if (getId() == 0x0000ffffffffff03L) { |
| 395 | final int inport = 31; |
| 396 | final int outport = 30; |
| 397 | //Circuit signal id |
| 398 | CircuitSignalID sigID = getSignalID(lambda); |
| 399 | |
| 400 | OFOxmOchSigid fieldSigIDMatch = factory().oxms().ochSigid(sigID); |
| 401 | OFOxmOchSigtype fieldSigType = factory() |
| 402 | .oxms() |
| 403 | .ochSigtype(SIGNAL_TYPE); |
| 404 | |
| 405 | OFOxmOchSigidBasic ofOxmOchSigidBasic = |
| 406 | factory().oxms().ochSigidBasic(sigID); |
| 407 | |
| 408 | //Match Port,SigType,SigID |
| 409 | OFOxmInPort fieldPort = factory() |
| 410 | .oxms() |
| 411 | .inPort(OFPort.of(inport)); |
| 412 | OFMatchV3 matchPort = factory() |
| 413 | .buildMatchV3() |
| 414 | .setOxmList(OFOxmList.of(fieldPort, |
| 415 | fieldSigIDMatch, |
| 416 | fieldSigType |
| 417 | )) |
| 418 | .build(); |
| 419 | |
| 420 | // Set Action outport ,SigType, sigID |
| 421 | List<OFAction> actionList = new ArrayList<>(); |
| 422 | OFAction actionOutPort = |
| 423 | factory().actions().output(OFPort.of(outport), |
| 424 | 0xffff); |
| 425 | OFActionCircuit actionCircuit = factory() |
| 426 | .actions() |
| 427 | .circuit(ofOxmOchSigidBasic); |
| 428 | |
| 429 | actionList.add(actionCircuit); |
| 430 | actionList.add(actionOutPort); |
| 431 | |
| 432 | OFInstruction instructionAction = |
| 433 | factory().instructions().buildApplyActions() |
| 434 | .setActions(actionList) |
| 435 | .build(); |
| 436 | List<OFInstruction> instructions = |
| 437 | Collections.singletonList(instructionAction); |
| 438 | |
| 439 | OFMessage opticalFlowEntry = |
| 440 | factory().buildFlowAdd() |
| 441 | .setMatch(matchPort) |
| 442 | .setPriority(100) |
| 443 | .setInstructions(instructions) |
| 444 | .setXid(getNextTransactionId()) |
| 445 | .build(); |
| 446 | log.debug("Adding optical flow in sw {}", getStringId()); |
| 447 | List<OFMessage> msglist = new ArrayList<>(1); |
| 448 | msglist.add(opticalFlowEntry); |
| 449 | write(msglist); |
| 450 | sendBarrier(true); |
| 451 | |
| 452 | } else if (getId() == 0x0000ffffffffff01L) { |
| 453 | final int inport = 20; |
| 454 | final int outport = 10; |
| 455 | //Circuit signal id |
| 456 | CircuitSignalID sigID = getSignalID(lambda); |
| 457 | |
| 458 | OFOxmOchSigid fieldSigIDMatch = factory().oxms().ochSigid(sigID); |
| 459 | OFOxmOchSigtype fieldSigType = factory() |
| 460 | .oxms() |
| 461 | .ochSigtype(SIGNAL_TYPE); |
| 462 | |
| 463 | |
| 464 | //Match Port, sig type and sig id |
| 465 | OFOxmInPort fieldPort = factory() |
| 466 | .oxms() |
| 467 | .inPort(OFPort.of(inport)); |
| 468 | OFMatchV3 matchPort = |
| 469 | factory().buildMatchV3() |
| 470 | .setOxmList(OFOxmList.of(fieldPort, |
| 471 | fieldSigIDMatch, |
| 472 | fieldSigType |
| 473 | )) |
| 474 | .build(); |
| 475 | |
| 476 | // Set Action outport |
| 477 | List<OFAction> actionList = new ArrayList<>(); |
| 478 | OFAction actionOutPort = |
| 479 | factory().actions().output(OFPort.of(outport), |
| 480 | 0xffff); |
| 481 | |
| 482 | actionList.add(actionOutPort); |
| 483 | |
| 484 | OFInstruction instructionAction = |
| 485 | factory().instructions().buildApplyActions() |
| 486 | .setActions(actionList) |
| 487 | .build(); |
| 488 | List<OFInstruction> instructions = |
| 489 | Collections.singletonList(instructionAction); |
| 490 | |
| 491 | OFMessage opticalFlowEntry = |
| 492 | factory().buildFlowAdd() |
| 493 | .setMatch(matchPort) |
| 494 | .setPriority(100) |
| 495 | .setInstructions(instructions) |
| 496 | .setXid(getNextTransactionId()) |
| 497 | .build(); |
| 498 | log.debug("Adding optical flow in sw {}", getStringId()); |
| 499 | List<OFMessage> msglist = new ArrayList<>(1); |
| 500 | msglist.add(opticalFlowEntry); |
| 501 | write(msglist); |
| 502 | sendBarrier(true); |
| 503 | } |
| 504 | |
| 505 | } |
| 506 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 507 | |
| 508 | // Todo remove - for testing purpose only |
| 509 | private static CircuitSignalID getSignalID(short lambda) { |
| 510 | byte myGrid = 1; |
| 511 | byte myCs = 2; |
| 512 | short myCn = lambda; |
| 513 | short mySw = 1; |
| 514 | |
| 515 | CircuitSignalID signalID = new CircuitSignalID(myGrid, |
| 516 | myCs, |
| 517 | myCn, |
| 518 | mySw); |
| 519 | return signalID; |
| 520 | } |
| 521 | |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 522 | private void sendBarrier(boolean finalBarrier) throws IOException { |
| 523 | int xid = getNextTransactionId(); |
| 524 | if (finalBarrier) { |
| 525 | barrierXidToWaitFor = xid; |
| 526 | } |
| 527 | OFBarrierRequest br = factory() |
| 528 | .buildBarrierRequest() |
| 529 | .setXid(xid) |
| 530 | .build(); |
| 531 | sendMsg(br); |
| 532 | } |
| 533 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 534 | @Override |
| 535 | public void write(OFMessage msg) { |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 536 | this.sendMsg(msg); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | @Override |
| 540 | public void write(List<OFMessage> msgs) { |
| 541 | this.channel.write(msgs); |
| 542 | } |
| 543 | |
| 544 | @Override |
| 545 | public Boolean supportNxRole() { |
| 546 | return false; |
| 547 | } |
| 548 | |
| 549 | } |