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 | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 8 | import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus; |
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; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 13 | import org.projectfloodlight.openflow.protocol.OFMessage; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 14 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 15 | import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 16 | import org.projectfloodlight.openflow.protocol.OFPortOptical; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 17 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
| 18 | import org.projectfloodlight.openflow.protocol.OFStatsType; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 19 | import org.slf4j.Logger; |
| 20 | import org.slf4j.LoggerFactory; |
| 21 | |
| 22 | import java.io.IOException; |
| 23 | import java.util.ArrayList; |
| 24 | import java.util.Collection; |
| 25 | import java.util.Collections; |
| 26 | import java.util.List; |
| 27 | import java.util.concurrent.atomic.AtomicBoolean; |
| 28 | |
| 29 | /** |
| 30 | * LINC-OE Optical Emulator switch class. |
| 31 | */ |
| 32 | public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch { |
| 33 | |
| 34 | private final AtomicBoolean driverHandshakeComplete; |
| 35 | private long barrierXidToWaitFor = -1; |
| 36 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 37 | private OFPortDescStatsReply wPorts; |
| 38 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 39 | private final Logger log = |
| 40 | LoggerFactory.getLogger(OFOpticalSwitchImplLINC13.class); |
| 41 | |
Yuta HIGUCHI | bccb6be | 2014-10-09 17:20:29 -0700 | [diff] [blame] | 42 | OFOpticalSwitchImplLINC13(Dpid dpid, OFDescStatsReply desc) { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 43 | super(dpid); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 44 | driverHandshakeComplete = new AtomicBoolean(false); |
| 45 | setSwitchDescription(desc); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public String toString() { |
| 50 | return "OFOpticalSwitchImplLINC13 [" + ((channel != null) |
| 51 | ? channel.getRemoteAddress() : "?") |
| 52 | + " DPID[" + ((getStringId() != null) ? getStringId() : "?") + "]]"; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public void startDriverHandshake() { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 57 | log.warn("Starting driver handshake for sw {}", getStringId()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 58 | if (startDriverHandshakeCalled) { |
| 59 | throw new SwitchDriverSubHandshakeAlreadyStarted(); |
| 60 | } |
| 61 | startDriverHandshakeCalled = true; |
| 62 | try { |
| 63 | sendHandshakeOFExperimenterPortDescRequest(); |
| 64 | } catch (IOException e) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 65 | log.error("LINC-OE exception while sending experimenter port desc:", |
| 66 | e.getMessage()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 67 | e.printStackTrace(); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public boolean isDriverHandshakeComplete() { |
| 73 | if (!startDriverHandshakeCalled) { |
| 74 | throw new SwitchDriverSubHandshakeNotStarted(); |
| 75 | } |
| 76 | return driverHandshakeComplete.get(); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public void processDriverHandshakeMessage(OFMessage m) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 81 | if (!startDriverHandshakeCalled) { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 82 | throw new SwitchDriverSubHandshakeNotStarted(); |
| 83 | } |
| 84 | if (driverHandshakeComplete.get()) { |
| 85 | throw new SwitchDriverSubHandshakeCompleted(m); |
| 86 | } |
| 87 | |
| 88 | switch (m.getType()) { |
| 89 | case BARRIER_REPLY: |
| 90 | if (m.getXid() == barrierXidToWaitFor) { |
| 91 | log.debug("LINC-OE Received barrier response"); |
| 92 | } |
| 93 | break; |
| 94 | case ERROR: |
| 95 | log.error("Switch {} Error {}", getStringId(), (OFErrorMsg) m); |
| 96 | break; |
| 97 | case FEATURES_REPLY: |
| 98 | break; |
| 99 | case FLOW_REMOVED: |
| 100 | break; |
| 101 | case GET_ASYNC_REPLY: |
| 102 | break; |
| 103 | case PACKET_IN: |
| 104 | break; |
| 105 | case PORT_STATUS: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 106 | log.warn("****LINC-OE Port Status {} {}", getStringId(), m); |
| 107 | processOFPortStatus((OFCircuitPortStatus) m); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 108 | break; |
| 109 | case QUEUE_GET_CONFIG_REPLY: |
| 110 | break; |
| 111 | case ROLE_REPLY: |
| 112 | break; |
| 113 | case STATS_REPLY: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 114 | OFStatsReply stats = (OFStatsReply) m; |
| 115 | if (stats.getStatsType() == OFStatsType.EXPERIMENTER) { |
| 116 | log.warn("LINC-OE : Received stats reply message {}", m); |
| 117 | processHandshakeOFExperimenterPortDescRequest( |
| 118 | (OFCircuitPortsReply) m); |
| 119 | driverHandshakeComplete.set(true); |
| 120 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 121 | break; |
| 122 | default: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 123 | log.warn("Received message {} during switch-driver " + |
| 124 | "subhandshake " + "from switch {} ... " + |
| 125 | "Ignoring message", m, |
| 126 | getStringId()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 127 | |
| 128 | } |
| 129 | } |
| 130 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 131 | //Todo |
| 132 | public void processOFPortStatus(OFCircuitPortStatus ps) { |
| 133 | log.debug("LINC-OE ..OF Port Status :", ps); |
| 134 | |
| 135 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 136 | |
| 137 | private void processHandshakeOFExperimenterPortDescRequest( |
| 138 | OFCircuitPortsReply sr) { |
| 139 | Collection<OFPortOptical> entries = sr.getEntries(); |
| 140 | List<OFPortDesc> ofPortDescList = new ArrayList<>(entries.size()); |
| 141 | for (OFPortOptical entry : entries) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 142 | log.warn("LINC:OE port message {}", entry.toString()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 143 | ofPortDescList.add(factory().buildPortDesc(). |
| 144 | setPortNo(entry.getPortNo()) |
| 145 | .setConfig(entry.getConfig()) |
| 146 | .setState(entry.getState()) |
| 147 | .setHwAddr(entry.getHwAddr()) |
| 148 | .setName(entry.getName()) |
| 149 | .build()); |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 150 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 151 | } |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 152 | setExperimenterPortDescReply(factory().buildPortDescStatsReply(). |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 153 | setEntries(ofPortDescList).build()); |
| 154 | } |
| 155 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 156 | private void setExperimenterPortDescReply(OFPortDescStatsReply reply) { |
| 157 | wPorts = reply; |
| 158 | } |
| 159 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 160 | |
| 161 | private void sendHandshakeOFExperimenterPortDescRequest() throws |
| 162 | IOException { |
| 163 | // send multi part message for port description for optical switches |
| 164 | OFCircuitPortsRequest circuitPortsRequest = factory() |
| 165 | .buildCircuitPortsRequest().setXid(getNextTransactionId()) |
| 166 | .build(); |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 167 | log.warn("LINC-OE : Sending experimented circuit port stats " + |
| 168 | "message " + |
| 169 | "{}", |
| 170 | circuitPortsRequest.toString()); |
| 171 | this.write(Collections.<OFMessage>singletonList(circuitPortsRequest)); |
| 172 | } |
| 173 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 174 | @Override |
| 175 | public List<OFPortDesc> getPorts() { |
| 176 | List<OFPortDesc> portEntries = new ArrayList<>(); |
| 177 | portEntries.addAll(ports.getEntries()); |
| 178 | if (wPorts != null) { |
| 179 | portEntries.addAll(wPorts.getEntries()); |
| 180 | } |
| 181 | return Collections.unmodifiableList(portEntries); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 184 | @Override |
| 185 | public void write(OFMessage msg) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 186 | this.channel.write(Collections.singletonList(msg)); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public void write(List<OFMessage> msgs) { |
| 191 | this.channel.write(msgs); |
| 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public Boolean supportNxRole() { |
| 196 | return false; |
| 197 | } |
| 198 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 199 | @Override |
| 200 | public boolean isOptical() { |
| 201 | return true; |
| 202 | } |
| 203 | |
| 204 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 205 | } |