blob: d805f970e0b679f1dddb4f81aeebfbf1df5ee7e2 [file] [log] [blame]
Mao Lu1f524702017-02-22 17:05:12 +08001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
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
7 *
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.
15 */
16package org.onosproject.driver.optical.handshaker;
17
18import com.google.common.collect.ImmutableList;
19import com.google.common.collect.ImmutableSet;
20
21import java.io.IOException;
22import java.util.ArrayList;
23import java.util.Collections;
24import java.util.List;
25import java.util.Set;
26import java.util.concurrent.atomic.AtomicBoolean;
27
28import org.onosproject.net.Device;
29import org.onosproject.net.device.PortDescription;
30import org.onosproject.openflow.controller.OpenFlowOpticalSwitch;
31import org.onosproject.openflow.controller.PortDescPropertyType;
32import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
33import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted;
34import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted;
35import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted;
36import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus;
37import org.projectfloodlight.openflow.protocol.OFCircuitPortsReply;
38import org.projectfloodlight.openflow.protocol.OFCircuitPortsRequest;
39import org.projectfloodlight.openflow.protocol.OFExpPortAdjacencyReply;
40import org.projectfloodlight.openflow.protocol.OFMessage;
41import org.projectfloodlight.openflow.protocol.OFObject;
42import org.projectfloodlight.openflow.protocol.OFPortDesc;
43import org.projectfloodlight.openflow.protocol.OFPortOptical;
44import org.projectfloodlight.openflow.protocol.OFStatsReply;
45import org.projectfloodlight.openflow.protocol.OFStatsRequest;
46import org.projectfloodlight.openflow.protocol.OFStatsType;
47import org.projectfloodlight.openflow.protocol.OFType;
48import org.projectfloodlight.openflow.protocol.OFOplinkPortPowerReply;
49
50import static org.onosproject.net.Device.Type;
51
52/**
53 * Driver for Oplink single WSS 8D ROADM.
54 *
55 * Driver implements custom handshaker and supports optical channel Port based on OpenFlow OTN extension.
56 * The device consists of Och ports, and performances wavelength cross-connect among the ports.
57 */
58public class OplinkRoadmHandshaker extends AbstractOpenFlowSwitch implements OpenFlowOpticalSwitch {
59
60 private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false);
61 private List<OFPortOptical> opticalPorts = new ArrayList<>();
62 private OplinkHandshakerUtil oplinkUtil = new OplinkHandshakerUtil(this);
63
64 @Override
65 public List<? extends OFObject> getPortsOf(PortDescPropertyType type) {
66 // Expected type is OPTICAL_TRANSPORT
67 if (type == PortDescPropertyType.OPTICAL_TRANSPORT) {
68 return ImmutableList.copyOf(opticalPorts);
69 }
70 // Any other type, return empty
71 log.warn("Unexpected port description property type: {}", type);
72 return ImmutableList.of();
73 }
74
75 /**
76 * Returns a list of standard (Ethernet) ports.
77 *
78 * @return List of ports
79 */
80 @Override
81 public List<OFPortDesc> getPorts() {
82 return ImmutableList.of();
83 }
84
85 @Override
86 public Set<PortDescPropertyType> getPortTypes() {
87 return ImmutableSet.of(PortDescPropertyType.OPTICAL_TRANSPORT);
88 }
89
90 @Override
91 public Boolean supportNxRole() {
92 return false;
93 }
94
95 @Override
96 public void startDriverHandshake() {
97 log.info("Starting driver handshake for sw {}", getStringId());
98 if (startDriverHandshakeCalled) {
99 throw new SwitchDriverSubHandshakeAlreadyStarted();
100 }
101 startDriverHandshakeCalled = true;
102 try {
103 sendHandshakeOFExperimenterPortDescRequest();
104 } catch (IOException e) {
105 log.error("OPLK ROADM exception while sending experimenter port desc:", e);
106 }
107 }
108
109 @Override
110 public boolean isDriverHandshakeComplete() {
111 return driverHandshakeComplete.get();
112 }
113
114 @Override
115 public void processDriverHandshakeMessage(OFMessage m) {
116
117 if (!startDriverHandshakeCalled) {
118 throw new SwitchDriverSubHandshakeNotStarted();
119 }
120
121 if (driverHandshakeComplete.get()) {
122 throw new SwitchDriverSubHandshakeCompleted(m);
123 }
124
125 switch (m.getType()) {
126 case BARRIER_REPLY:
127 log.debug("OPLK ROADM Received barrier response");
128 break;
129 case ERROR:
130 log.error("Switch {} Error {}", getStringId(), m);
131 break;
132 case FEATURES_REPLY:
133 break;
134 case FLOW_REMOVED:
135 break;
136 case GET_ASYNC_REPLY:
137 break;
138 case PACKET_IN:
139 break;
140 case PORT_STATUS:
141 processOFPortStatus((OFCircuitPortStatus) m);
142 break;
143 case QUEUE_GET_CONFIG_REPLY:
144 break;
145 case ROLE_REPLY:
146 break;
147 case STATS_REPLY:
148 OFStatsReply stats = (OFStatsReply) m;
149 if (stats.getStatsType() == OFStatsType.EXPERIMENTER) {
150 log.debug("OPLK ROADM : Received multipart (port desc) reply message {}", m);
151 //OTN Optical extension 1.0 port-desc
152 createOpticalPortList((OFCircuitPortsReply) m);
153 driverHandshakeComplete.set(true);
154 }
155 break;
156 default:
157 log.warn("Received message {} during switch-driver " +
158 "subhandshake from switch {} ... " +
159 "Ignoring message", m, getStringId());
160
161 }
162 }
163
164 @Override
165 public Device.Type deviceType() {
166 return Type.ROADM;
167 }
168
169 @Override
170 public final void sendMsg(OFMessage m) {
171 List<OFMessage> messages = new ArrayList<>();
172 messages.add(m);
173
174 if (m.getType() == OFType.STATS_REQUEST) {
175 OFStatsRequest sr = (OFStatsRequest) m;
176 log.debug("OPLK ROADM rebuilding stats request type {}", sr.getStatsType());
177 switch (sr.getStatsType()) {
178 case PORT:
179 // add Oplink experiment message to get the port's current power
180 messages.add(oplinkUtil.buildPortPowerRequest());
181 // add experiment message to get adjacent ports
182 messages.add(oplinkUtil.buildPortAdjacencyRequest());
183 break;
184 default:
185 break;
186 }
187 } else {
188 log.debug("OPLK ROADM sends msg:{}, as is", m.getType());
189 }
190
191 super.sendMsg(messages);
192 }
193
194 @Override
195 public List<PortDescription> processExpPortStats(OFMessage msg) {
196 if (msg instanceof OFOplinkPortPowerReply) {
197 return oplinkUtil.buildPortPowerDescriptions(((OFOplinkPortPowerReply) msg).getEntries());
198 } else if (msg instanceof OFExpPortAdjacencyReply) {
199 return oplinkUtil.buildPortAdjacencyDescriptions(((OFExpPortAdjacencyReply) msg).getEntries());
200 }
201 return Collections.emptyList();
202 }
203
204 private void processOFPortStatus(OFCircuitPortStatus ps) {
205 log.debug("OPLK ROADM ..OF Port Status :", ps);
206 }
207
208 private void sendHandshakeOFExperimenterPortDescRequest() throws IOException {
209 // Send multipart message for port description for optical switches
210 OFCircuitPortsRequest circuitPortsRequest = oplinkUtil.buildCircuitPortsRequest();
211 log.debug("OPLK ROADM : Sending experimented port description message {}", circuitPortsRequest);
212 sendHandshakeMessage(circuitPortsRequest);
213 }
214
215 /**
216 * Builds list of OFPortOptical ports based on the multi-part circuit ports reply.
217 * Ensure the optical transport port's signal type is configured correctly.
218 *
219 * @param wPorts OF reply with circuit ports
220 */
221 private void createOpticalPortList(OFCircuitPortsReply wPorts) {
222 opticalPorts.addAll(wPorts.getEntries());
223 }
224
225}