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 | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 9 | import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 10 | import org.projectfloodlight.openflow.protocol.OFCircuitPortsReply; |
| 11 | import org.projectfloodlight.openflow.protocol.OFCircuitPortsRequest; |
| 12 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| 13 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
| 14 | import org.projectfloodlight.openflow.protocol.OFMatchV3; |
| 15 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 16 | import org.projectfloodlight.openflow.protocol.OFOxmList; |
| 17 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 18 | import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 19 | import org.projectfloodlight.openflow.protocol.OFPortOptical; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 20 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
| 21 | import org.projectfloodlight.openflow.protocol.OFStatsType; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 22 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
| 23 | import org.projectfloodlight.openflow.protocol.action.OFActionCircuit; |
| 24 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
| 25 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmInPort; |
| 26 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid; |
| 27 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic; |
| 28 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigtype; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 29 | import org.projectfloodlight.openflow.types.CircuitSignalID; |
| 30 | import org.projectfloodlight.openflow.types.OFPort; |
| 31 | import org.projectfloodlight.openflow.types.U8; |
| 32 | import org.slf4j.Logger; |
| 33 | import org.slf4j.LoggerFactory; |
| 34 | |
| 35 | import java.io.IOException; |
| 36 | import java.util.ArrayList; |
| 37 | import java.util.Collection; |
| 38 | import java.util.Collections; |
| 39 | import java.util.List; |
| 40 | import java.util.concurrent.atomic.AtomicBoolean; |
| 41 | |
| 42 | /** |
| 43 | * LINC-OE Optical Emulator switch class. |
| 44 | */ |
| 45 | public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch { |
| 46 | |
| 47 | private final AtomicBoolean driverHandshakeComplete; |
| 48 | private long barrierXidToWaitFor = -1; |
| 49 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 50 | private OFPortDescStatsReply wPorts; |
| 51 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 52 | private final Logger log = |
| 53 | LoggerFactory.getLogger(OFOpticalSwitchImplLINC13.class); |
| 54 | |
Yuta HIGUCHI | bccb6be | 2014-10-09 17:20:29 -0700 | [diff] [blame] | 55 | OFOpticalSwitchImplLINC13(Dpid dpid, OFDescStatsReply desc) { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 56 | super(dpid); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 57 | 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 Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 70 | log.warn("Starting driver handshake for sw {}", getStringId()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 71 | if (startDriverHandshakeCalled) { |
| 72 | throw new SwitchDriverSubHandshakeAlreadyStarted(); |
| 73 | } |
| 74 | startDriverHandshakeCalled = true; |
| 75 | try { |
| 76 | sendHandshakeOFExperimenterPortDescRequest(); |
| 77 | } catch (IOException e) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 78 | log.error("LINC-OE exception while sending experimenter port desc:", |
| 79 | e.getMessage()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 80 | 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 Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 94 | if (!startDriverHandshakeCalled) { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 95 | 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 Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 119 | log.warn("****LINC-OE Port Status {} {}", getStringId(), m); |
| 120 | processOFPortStatus((OFCircuitPortStatus) m); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 121 | break; |
| 122 | case QUEUE_GET_CONFIG_REPLY: |
| 123 | break; |
| 124 | case ROLE_REPLY: |
| 125 | break; |
| 126 | case STATS_REPLY: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 127 | 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 Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 135 | testMA(); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 136 | testReverseMA(); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 137 | } catch (IOException e) { |
| 138 | e.printStackTrace(); |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 139 | }*/ |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 140 | break; |
| 141 | default: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 142 | log.warn("Received message {} during switch-driver " + |
| 143 | "subhandshake " + "from switch {} ... " + |
| 144 | "Ignoring message", m, |
| 145 | getStringId()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 146 | |
| 147 | } |
| 148 | } |
| 149 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 150 | //Todo |
| 151 | public void processOFPortStatus(OFCircuitPortStatus ps) { |
| 152 | log.debug("LINC-OE ..OF Port Status :", ps); |
| 153 | |
| 154 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 155 | |
| 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 Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 161 | log.warn("LINC:OE port message {}", entry.toString()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 162 | 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 Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 169 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 170 | } |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 171 | setExperimenterPortDescReply(factory().buildPortDescStatsReply(). |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 172 | setEntries(ofPortDescList).build()); |
| 173 | } |
| 174 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 175 | private void setExperimenterPortDescReply(OFPortDescStatsReply reply) { |
| 176 | wPorts = reply; |
| 177 | } |
| 178 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 179 | |
| 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 Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 186 | 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 Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 205 | public static final U8 SIGNAL_TYPE = U8.of((short) 10); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 206 | private void testMA() throws IOException { |
| 207 | log.debug("LINC OE *** Testing MA "); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 208 | short lambda = 1; |
| 209 | if (getId() == 0x0000ffffffffff01L) { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 210 | final int inport = 10; |
| 211 | final int outport = 20; |
| 212 | //Circuit signal id |
| 213 | CircuitSignalID sigID = getSignalID(lambda); |
| 214 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 215 | OFOxmOchSigidBasic ofOxmOchSigidBasic = |
| 216 | factory().oxms().ochSigidBasic(sigID); |
| 217 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 218 | |
| 219 | //Match Port |
| 220 | OFOxmInPort fieldPort = factory().oxms() |
| 221 | .inPort(OFPort.of(inport)); |
| 222 | OFMatchV3 matchPort = |
| 223 | factory() |
| 224 | .buildMatchV3(). |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 225 | setOxmList(OFOxmList.of(fieldPort)).build(); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 226 | |
| 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 Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 232 | 0xffff); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 233 | |
| 234 | OFActionCircuit actionCircuit = factory() |
| 235 | .actions() |
| 236 | .circuit(ofOxmOchSigidBasic); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 237 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 238 | actionList.add(actionCircuit); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 239 | actionList.add(actionOutPort); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 240 | |
| 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 Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 251 | .setPriority(100) |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 252 | .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 Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 259 | sendBarrier(true); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 260 | } else if (getId() == 0x0000ffffffffff03L) { |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 261 | final int inport = 30; |
| 262 | final int outport = 31; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 263 | //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 Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 274 | //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 Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 281 | fieldSigIDMatch, |
| 282 | fieldSigType |
| 283 | )) |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 284 | .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 Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 290 | 0xffff); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 291 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 292 | OFActionCircuit actionCircuit = factory() |
| 293 | .actions() |
| 294 | .circuit(ofOxmOchSigidBasic); |
| 295 | |
| 296 | |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 297 | |
| 298 | //actionList.add(setActionSigType); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 299 | actionList.add(actionCircuit); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 300 | actionList.add(actionOutPort); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 301 | |
| 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 Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 311 | .setMatch(matchPort) |
| 312 | .setPriority(100) |
| 313 | .setInstructions(instructions) |
| 314 | .setXid(getNextTransactionId()) |
| 315 | .build(); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 316 | log.debug("Adding optical flow in sw {}", getStringId()); |
| 317 | List<OFMessage> msglist = new ArrayList<>(1); |
| 318 | msglist.add(opticalFlowEntry); |
| 319 | write(msglist); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 320 | sendBarrier(true); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 321 | |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 322 | } else if (getId() == 0x0000ffffffffff02L) { |
| 323 | final int inport = 21; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 324 | 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 Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 341 | fieldSigIDMatch, |
| 342 | fieldSigType |
| 343 | )) |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 344 | .build(); |
| 345 | |
| 346 | // Set Action outport |
| 347 | List<OFAction> actionList = new ArrayList<>(); |
| 348 | OFAction actionOutPort = |
| 349 | factory().actions().output(OFPort.of(outport), |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 350 | 0xffff); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 351 | |
| 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 Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 363 | .setMatch(matchPort) |
| 364 | .setPriority(100) |
| 365 | .setInstructions(instructions) |
| 366 | .setXid(getNextTransactionId()) |
| 367 | .build(); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 368 | log.debug("Adding optical flow in sw {}", getStringId()); |
| 369 | List<OFMessage> msglist = new ArrayList<>(1); |
| 370 | msglist.add(opticalFlowEntry); |
| 371 | write(msglist); |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 372 | sendBarrier(true); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | } |
Praseed Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 376 | 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 Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 541 | |
| 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 Balakrishnan | 610c1e1 | 2014-10-15 16:34:59 -0700 | [diff] [blame] | 556 | 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 Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 568 | @Override |
| 569 | public void write(OFMessage msg) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 570 | this.channel.write(Collections.singletonList(msg)); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 571 | } |
| 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 Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame^] | 583 | @Override |
| 584 | public boolean isOptical() { |
| 585 | return true; |
| 586 | } |
| 587 | |
| 588 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 589 | } |