Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 19 | package org.onlab.onos.openflow.drivers.impl; |
| 20 | |
| 21 | import org.onlab.onos.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted; |
| 22 | import org.onlab.onos.openflow.controller.driver.SwitchDriverSubHandshakeCompleted; |
| 23 | import org.onlab.onos.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted; |
| 24 | import org.onlab.onos.openflow.controller.Dpid; |
| 25 | import org.onlab.onos.openflow.controller.driver.AbstractOpenFlowSwitch; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 26 | import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 27 | import org.projectfloodlight.openflow.protocol.OFCircuitPortsReply; |
| 28 | import org.projectfloodlight.openflow.protocol.OFCircuitPortsRequest; |
| 29 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 30 | import org.projectfloodlight.openflow.protocol.OFMessage; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 31 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 32 | import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 33 | import org.projectfloodlight.openflow.protocol.OFPortOptical; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 34 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
| 35 | import org.projectfloodlight.openflow.protocol.OFStatsType; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 36 | import java.io.IOException; |
| 37 | import java.util.ArrayList; |
| 38 | import java.util.Collection; |
| 39 | import java.util.Collections; |
| 40 | import java.util.List; |
| 41 | import java.util.concurrent.atomic.AtomicBoolean; |
| 42 | |
| 43 | /** |
| 44 | * LINC-OE Optical Emulator switch class. |
| 45 | */ |
| 46 | public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch { |
| 47 | |
| 48 | private final AtomicBoolean driverHandshakeComplete; |
| 49 | private long barrierXidToWaitFor = -1; |
| 50 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 51 | private OFPortDescStatsReply wPorts; |
| 52 | |
Yuta HIGUCHI | bccb6be | 2014-10-09 17:20:29 -0700 | [diff] [blame] | 53 | OFOpticalSwitchImplLINC13(Dpid dpid, OFDescStatsReply desc) { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 54 | super(dpid); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 55 | driverHandshakeComplete = new AtomicBoolean(false); |
| 56 | setSwitchDescription(desc); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public String toString() { |
| 61 | return "OFOpticalSwitchImplLINC13 [" + ((channel != null) |
| 62 | ? channel.getRemoteAddress() : "?") |
| 63 | + " DPID[" + ((getStringId() != null) ? getStringId() : "?") + "]]"; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public void startDriverHandshake() { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 68 | log.warn("Starting driver handshake for sw {}", getStringId()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 69 | if (startDriverHandshakeCalled) { |
| 70 | throw new SwitchDriverSubHandshakeAlreadyStarted(); |
| 71 | } |
| 72 | startDriverHandshakeCalled = true; |
| 73 | try { |
| 74 | sendHandshakeOFExperimenterPortDescRequest(); |
| 75 | } catch (IOException e) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 76 | log.error("LINC-OE exception while sending experimenter port desc:", |
| 77 | e.getMessage()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 78 | e.printStackTrace(); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public boolean isDriverHandshakeComplete() { |
| 84 | if (!startDriverHandshakeCalled) { |
| 85 | throw new SwitchDriverSubHandshakeNotStarted(); |
| 86 | } |
| 87 | return driverHandshakeComplete.get(); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public void processDriverHandshakeMessage(OFMessage m) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 92 | if (!startDriverHandshakeCalled) { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 93 | throw new SwitchDriverSubHandshakeNotStarted(); |
| 94 | } |
| 95 | if (driverHandshakeComplete.get()) { |
| 96 | throw new SwitchDriverSubHandshakeCompleted(m); |
| 97 | } |
| 98 | |
| 99 | switch (m.getType()) { |
| 100 | case BARRIER_REPLY: |
| 101 | if (m.getXid() == barrierXidToWaitFor) { |
| 102 | log.debug("LINC-OE Received barrier response"); |
| 103 | } |
| 104 | break; |
| 105 | case ERROR: |
Yuta HIGUCHI | f5416d8 | 2014-10-24 21:17:40 -0700 | [diff] [blame] | 106 | log.error("Switch {} Error {}", getStringId(), m); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 107 | break; |
| 108 | case FEATURES_REPLY: |
| 109 | break; |
| 110 | case FLOW_REMOVED: |
| 111 | break; |
| 112 | case GET_ASYNC_REPLY: |
| 113 | break; |
| 114 | case PACKET_IN: |
| 115 | break; |
| 116 | case PORT_STATUS: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 117 | log.warn("****LINC-OE Port Status {} {}", getStringId(), m); |
| 118 | processOFPortStatus((OFCircuitPortStatus) m); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 119 | break; |
| 120 | case QUEUE_GET_CONFIG_REPLY: |
| 121 | break; |
| 122 | case ROLE_REPLY: |
| 123 | break; |
| 124 | case STATS_REPLY: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 125 | OFStatsReply stats = (OFStatsReply) m; |
| 126 | if (stats.getStatsType() == OFStatsType.EXPERIMENTER) { |
| 127 | log.warn("LINC-OE : Received stats reply message {}", m); |
| 128 | processHandshakeOFExperimenterPortDescRequest( |
| 129 | (OFCircuitPortsReply) m); |
| 130 | driverHandshakeComplete.set(true); |
| 131 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 132 | break; |
| 133 | default: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 134 | log.warn("Received message {} during switch-driver " + |
| 135 | "subhandshake " + "from switch {} ... " + |
| 136 | "Ignoring message", m, |
| 137 | getStringId()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 138 | |
| 139 | } |
| 140 | } |
| 141 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 142 | //Todo |
| 143 | public void processOFPortStatus(OFCircuitPortStatus ps) { |
| 144 | log.debug("LINC-OE ..OF Port Status :", ps); |
| 145 | |
| 146 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 147 | |
| 148 | private void processHandshakeOFExperimenterPortDescRequest( |
| 149 | OFCircuitPortsReply sr) { |
| 150 | Collection<OFPortOptical> entries = sr.getEntries(); |
| 151 | List<OFPortDesc> ofPortDescList = new ArrayList<>(entries.size()); |
| 152 | for (OFPortOptical entry : entries) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 153 | log.warn("LINC:OE port message {}", entry.toString()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 154 | ofPortDescList.add(factory().buildPortDesc(). |
| 155 | setPortNo(entry.getPortNo()) |
| 156 | .setConfig(entry.getConfig()) |
| 157 | .setState(entry.getState()) |
| 158 | .setHwAddr(entry.getHwAddr()) |
| 159 | .setName(entry.getName()) |
| 160 | .build()); |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 161 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 162 | } |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 163 | setExperimenterPortDescReply(factory().buildPortDescStatsReply(). |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 164 | setEntries(ofPortDescList).build()); |
| 165 | } |
| 166 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 167 | private void setExperimenterPortDescReply(OFPortDescStatsReply reply) { |
| 168 | wPorts = reply; |
| 169 | } |
| 170 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 171 | |
| 172 | private void sendHandshakeOFExperimenterPortDescRequest() throws |
| 173 | IOException { |
| 174 | // send multi part message for port description for optical switches |
| 175 | OFCircuitPortsRequest circuitPortsRequest = factory() |
| 176 | .buildCircuitPortsRequest().setXid(getNextTransactionId()) |
| 177 | .build(); |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 178 | log.warn("LINC-OE : Sending experimented circuit port stats " + |
| 179 | "message " + |
| 180 | "{}", |
| 181 | circuitPortsRequest.toString()); |
| 182 | this.write(Collections.<OFMessage>singletonList(circuitPortsRequest)); |
| 183 | } |
| 184 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 185 | @Override |
| 186 | public List<OFPortDesc> getPorts() { |
| 187 | List<OFPortDesc> portEntries = new ArrayList<>(); |
| 188 | portEntries.addAll(ports.getEntries()); |
| 189 | if (wPorts != null) { |
| 190 | portEntries.addAll(wPorts.getEntries()); |
| 191 | } |
| 192 | return Collections.unmodifiableList(portEntries); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 195 | @Override |
| 196 | public void write(OFMessage msg) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 197 | this.channel.write(Collections.singletonList(msg)); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public void write(List<OFMessage> msgs) { |
| 202 | this.channel.write(msgs); |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public Boolean supportNxRole() { |
| 207 | return false; |
| 208 | } |
| 209 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 210 | @Override |
| 211 | public boolean isOptical() { |
| 212 | return true; |
| 213 | } |
| 214 | |
| 215 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 216 | } |