Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.openflow.drivers; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 18 | import org.onosproject.openflow.controller.Dpid; |
| 19 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; |
| 20 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted; |
| 21 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted; |
| 22 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted; |
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; |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 33 | import org.projectfloodlight.openflow.types.TableId; |
alshabib | 452234e | 2014-11-25 00:03:49 -0500 | [diff] [blame] | 34 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 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 | |
Yuta HIGUCHI | bccb6be | 2014-10-09 17:20:29 -0700 | [diff] [blame] | 52 | OFOpticalSwitchImplLINC13(Dpid dpid, OFDescStatsReply desc) { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 53 | super(dpid); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 54 | driverHandshakeComplete = new AtomicBoolean(false); |
| 55 | setSwitchDescription(desc); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public String toString() { |
| 60 | return "OFOpticalSwitchImplLINC13 [" + ((channel != null) |
| 61 | ? channel.getRemoteAddress() : "?") |
| 62 | + " DPID[" + ((getStringId() != null) ? getStringId() : "?") + "]]"; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public void startDriverHandshake() { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 67 | log.warn("Starting driver handshake for sw {}", getStringId()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 68 | if (startDriverHandshakeCalled) { |
| 69 | throw new SwitchDriverSubHandshakeAlreadyStarted(); |
| 70 | } |
| 71 | startDriverHandshakeCalled = true; |
| 72 | try { |
| 73 | sendHandshakeOFExperimenterPortDescRequest(); |
| 74 | } catch (IOException e) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 75 | log.error("LINC-OE exception while sending experimenter port desc:", |
| 76 | e.getMessage()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 77 | e.printStackTrace(); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public boolean isDriverHandshakeComplete() { |
| 83 | if (!startDriverHandshakeCalled) { |
| 84 | throw new SwitchDriverSubHandshakeNotStarted(); |
| 85 | } |
| 86 | return driverHandshakeComplete.get(); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public void processDriverHandshakeMessage(OFMessage m) { |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 91 | if (!startDriverHandshakeCalled) { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 92 | throw new SwitchDriverSubHandshakeNotStarted(); |
| 93 | } |
| 94 | if (driverHandshakeComplete.get()) { |
| 95 | throw new SwitchDriverSubHandshakeCompleted(m); |
| 96 | } |
| 97 | |
| 98 | switch (m.getType()) { |
| 99 | case BARRIER_REPLY: |
| 100 | if (m.getXid() == barrierXidToWaitFor) { |
| 101 | log.debug("LINC-OE Received barrier response"); |
| 102 | } |
| 103 | break; |
| 104 | case ERROR: |
Yuta HIGUCHI | f5416d8 | 2014-10-24 21:17:40 -0700 | [diff] [blame] | 105 | log.error("Switch {} Error {}", getStringId(), m); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 106 | break; |
| 107 | case FEATURES_REPLY: |
| 108 | break; |
| 109 | case FLOW_REMOVED: |
| 110 | break; |
| 111 | case GET_ASYNC_REPLY: |
| 112 | break; |
| 113 | case PACKET_IN: |
| 114 | break; |
| 115 | case PORT_STATUS: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 116 | log.warn("****LINC-OE Port Status {} {}", getStringId(), m); |
| 117 | processOFPortStatus((OFCircuitPortStatus) m); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 118 | break; |
| 119 | case QUEUE_GET_CONFIG_REPLY: |
| 120 | break; |
| 121 | case ROLE_REPLY: |
| 122 | break; |
| 123 | case STATS_REPLY: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 124 | OFStatsReply stats = (OFStatsReply) m; |
| 125 | if (stats.getStatsType() == OFStatsType.EXPERIMENTER) { |
| 126 | log.warn("LINC-OE : Received stats reply message {}", m); |
| 127 | processHandshakeOFExperimenterPortDescRequest( |
| 128 | (OFCircuitPortsReply) m); |
| 129 | driverHandshakeComplete.set(true); |
| 130 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 131 | break; |
| 132 | default: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 133 | log.warn("Received message {} during switch-driver " + |
| 134 | "subhandshake " + "from switch {} ... " + |
| 135 | "Ignoring message", m, |
| 136 | getStringId()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 137 | |
| 138 | } |
| 139 | } |
| 140 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 141 | public void processOFPortStatus(OFCircuitPortStatus ps) { |
| 142 | log.debug("LINC-OE ..OF Port Status :", ps); |
| 143 | |
| 144 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 145 | |
| 146 | private void processHandshakeOFExperimenterPortDescRequest( |
| 147 | OFCircuitPortsReply sr) { |
| 148 | Collection<OFPortOptical> entries = sr.getEntries(); |
| 149 | List<OFPortDesc> ofPortDescList = new ArrayList<>(entries.size()); |
| 150 | for (OFPortOptical entry : entries) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 151 | log.warn("LINC:OE port message {}", entry.toString()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 152 | ofPortDescList.add(factory().buildPortDesc(). |
| 153 | setPortNo(entry.getPortNo()) |
| 154 | .setConfig(entry.getConfig()) |
| 155 | .setState(entry.getState()) |
| 156 | .setHwAddr(entry.getHwAddr()) |
| 157 | .setName(entry.getName()) |
| 158 | .build()); |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 159 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 160 | } |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 161 | setExperimenterPortDescReply(factory().buildPortDescStatsReply(). |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 162 | setEntries(ofPortDescList).build()); |
| 163 | } |
| 164 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 165 | private void setExperimenterPortDescReply(OFPortDescStatsReply reply) { |
| 166 | wPorts = reply; |
| 167 | } |
| 168 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 169 | |
| 170 | private void sendHandshakeOFExperimenterPortDescRequest() throws |
| 171 | IOException { |
| 172 | // send multi part message for port description for optical switches |
| 173 | OFCircuitPortsRequest circuitPortsRequest = factory() |
| 174 | .buildCircuitPortsRequest().setXid(getNextTransactionId()) |
| 175 | .build(); |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 176 | log.warn("LINC-OE : Sending experimented circuit port stats " + |
| 177 | "message " + |
| 178 | "{}", |
| 179 | circuitPortsRequest.toString()); |
| 180 | this.write(Collections.<OFMessage>singletonList(circuitPortsRequest)); |
| 181 | } |
| 182 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 183 | @Override |
| 184 | public List<OFPortDesc> getPorts() { |
| 185 | List<OFPortDesc> portEntries = new ArrayList<>(); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 186 | portEntries.addAll(super.getPorts()); |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 187 | if (wPorts != null) { |
| 188 | portEntries.addAll(wPorts.getEntries()); |
| 189 | } |
| 190 | return Collections.unmodifiableList(portEntries); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 193 | @Override |
| 194 | public void write(OFMessage msg) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 195 | this.channel.write(Collections.singletonList(msg)); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | @Override |
| 199 | public void write(List<OFMessage> msgs) { |
| 200 | this.channel.write(msgs); |
| 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public Boolean supportNxRole() { |
| 205 | return false; |
| 206 | } |
| 207 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 208 | @Override |
| 209 | public boolean isOptical() { |
| 210 | return true; |
| 211 | } |
| 212 | |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 213 | @Override |
| 214 | public TableType getTableType(TableId tid) { |
| 215 | return TableType.NONE; |
| 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public void transformAndSendMsg(OFMessage msg, TableType tableType) { |
| 220 | // TODO Auto-generated method stub |
| 221 | |
| 222 | } |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 223 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 224 | } |