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 | |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 18 | import org.onosproject.net.Device; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 19 | import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; |
| 20 | import org.onosproject.openflow.controller.PortDescPropertyType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; |
| 22 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted; |
| 23 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted; |
| 24 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 25 | import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 26 | import org.projectfloodlight.openflow.protocol.OFCircuitPortsReply; |
| 27 | import org.projectfloodlight.openflow.protocol.OFCircuitPortsRequest; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 28 | import org.projectfloodlight.openflow.protocol.OFMessage; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 29 | import org.projectfloodlight.openflow.protocol.OFObject; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 30 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
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; |
alshabib | 452234e | 2014-11-25 00:03:49 -0500 | [diff] [blame] | 33 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 34 | import com.google.common.collect.ImmutableList; |
| 35 | import com.google.common.collect.ImmutableSet; |
| 36 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 37 | import java.io.IOException; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 38 | import java.util.List; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 39 | import java.util.Set; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 40 | import java.util.concurrent.atomic.AtomicBoolean; |
| 41 | |
| 42 | /** |
| 43 | * LINC-OE Optical Emulator switch class. |
| 44 | */ |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 45 | public class OFOpticalSwitchImplLINC13 |
| 46 | extends AbstractOpenFlowSwitch implements OpenFlowOpticalSwitch { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 47 | |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 48 | private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 49 | private long barrierXidToWaitFor = -1; |
| 50 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 51 | private OFCircuitPortsReply wPorts; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 52 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 53 | @Override |
| 54 | public void startDriverHandshake() { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 55 | log.warn("Starting driver handshake for sw {}", getStringId()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 56 | if (startDriverHandshakeCalled) { |
| 57 | throw new SwitchDriverSubHandshakeAlreadyStarted(); |
| 58 | } |
| 59 | startDriverHandshakeCalled = true; |
| 60 | try { |
| 61 | sendHandshakeOFExperimenterPortDescRequest(); |
| 62 | } catch (IOException e) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 63 | log.error("LINC-OE exception while sending experimenter port desc:", |
| 64 | e.getMessage()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 65 | e.printStackTrace(); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public boolean isDriverHandshakeComplete() { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 71 | return driverHandshakeComplete.get(); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public void processDriverHandshakeMessage(OFMessage m) { |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 76 | if (!startDriverHandshakeCalled) { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 77 | throw new SwitchDriverSubHandshakeNotStarted(); |
| 78 | } |
| 79 | if (driverHandshakeComplete.get()) { |
| 80 | throw new SwitchDriverSubHandshakeCompleted(m); |
| 81 | } |
| 82 | |
| 83 | switch (m.getType()) { |
| 84 | case BARRIER_REPLY: |
| 85 | if (m.getXid() == barrierXidToWaitFor) { |
| 86 | log.debug("LINC-OE Received barrier response"); |
| 87 | } |
| 88 | break; |
| 89 | case ERROR: |
Yuta HIGUCHI | f5416d8 | 2014-10-24 21:17:40 -0700 | [diff] [blame] | 90 | log.error("Switch {} Error {}", getStringId(), m); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 91 | break; |
| 92 | case FEATURES_REPLY: |
| 93 | break; |
| 94 | case FLOW_REMOVED: |
| 95 | break; |
| 96 | case GET_ASYNC_REPLY: |
| 97 | break; |
| 98 | case PACKET_IN: |
| 99 | break; |
| 100 | case PORT_STATUS: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 101 | log.warn("****LINC-OE Port Status {} {}", getStringId(), m); |
| 102 | processOFPortStatus((OFCircuitPortStatus) m); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 103 | break; |
| 104 | case QUEUE_GET_CONFIG_REPLY: |
| 105 | break; |
| 106 | case ROLE_REPLY: |
| 107 | break; |
| 108 | case STATS_REPLY: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 109 | OFStatsReply stats = (OFStatsReply) m; |
| 110 | if (stats.getStatsType() == OFStatsType.EXPERIMENTER) { |
| 111 | log.warn("LINC-OE : Received stats reply message {}", m); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 112 | wPorts = (OFCircuitPortsReply) m; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 113 | driverHandshakeComplete.set(true); |
| 114 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 115 | break; |
| 116 | default: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 117 | log.warn("Received message {} during switch-driver " + |
| 118 | "subhandshake " + "from switch {} ... " + |
| 119 | "Ignoring message", m, |
| 120 | getStringId()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 121 | |
| 122 | } |
| 123 | } |
| 124 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 125 | public void processOFPortStatus(OFCircuitPortStatus ps) { |
| 126 | log.debug("LINC-OE ..OF Port Status :", ps); |
| 127 | |
| 128 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 129 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 130 | private void sendHandshakeOFExperimenterPortDescRequest() throws |
| 131 | IOException { |
| 132 | // send multi part message for port description for optical switches |
| 133 | OFCircuitPortsRequest circuitPortsRequest = factory() |
| 134 | .buildCircuitPortsRequest().setXid(getNextTransactionId()) |
| 135 | .build(); |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 136 | log.warn("LINC-OE : Sending experimented circuit port stats " + |
| 137 | "message " + |
| 138 | "{}", |
| 139 | circuitPortsRequest.toString()); |
alshabib | a2df7b2a | 2015-05-06 13:57:10 -0700 | [diff] [blame] | 140 | this.sendHandshakeMessage(circuitPortsRequest); |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 143 | @Override |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 144 | /** |
| 145 | * Returns a list of standard (Ethernet) ports. |
| 146 | * |
| 147 | * @return List of ports |
| 148 | */ |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 149 | public List<OFPortDesc> getPorts() { |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 150 | return ImmutableList.copyOf(super.getPorts()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 153 | |
| 154 | @Override |
| 155 | public Boolean supportNxRole() { |
| 156 | return false; |
| 157 | } |
| 158 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 159 | @Override |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 160 | public Device.Type deviceType() { |
| 161 | return Device.Type.ROADM; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 164 | @Override |
| 165 | public List<? extends OFObject> getPortsOf(PortDescPropertyType type) { |
| 166 | return ImmutableList.copyOf(wPorts.getEntries()); |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public Set<PortDescPropertyType> getPortTypes() { |
| 171 | return ImmutableSet.of(PortDescPropertyType.OPTICAL_TRANSPORT); |
| 172 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 173 | } |