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