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