blob: 4ea2f7103d2b245235eaa438706cd59927737a56 [file] [log] [blame]
tom7ef8ff92014-09-17 13:08:06 -07001//CHECKSTYLE:OFF
tom9c94c5b2014-09-17 13:14:42 -07002package org.onlab.onos.openflow.controller.impl;
tom7ef8ff92014-09-17 13:08:06 -07003
4import java.io.IOException;
5import java.nio.channels.ClosedChannelException;
6import java.util.ArrayList;
7import java.util.Collections;
8import java.util.List;
9import java.util.concurrent.CopyOnWriteArrayList;
10import java.util.concurrent.RejectedExecutionException;
11
12import org.jboss.netty.channel.Channel;
13import org.jboss.netty.channel.ChannelHandlerContext;
14import org.jboss.netty.channel.ChannelStateEvent;
15import org.jboss.netty.channel.ExceptionEvent;
16import org.jboss.netty.channel.MessageEvent;
17import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler;
18import org.jboss.netty.handler.timeout.IdleStateEvent;
19import org.jboss.netty.handler.timeout.ReadTimeoutException;
tom9c94c5b2014-09-17 13:14:42 -070020import org.onlab.onos.openflow.controller.driver.OpenFlowSwitchDriver;
21import org.onlab.onos.openflow.controller.driver.SwitchStateException;
tom7ef8ff92014-09-17 13:08:06 -070022import org.projectfloodlight.openflow.exceptions.OFParseError;
23import org.projectfloodlight.openflow.protocol.OFAsyncGetReply;
24import org.projectfloodlight.openflow.protocol.OFBadRequestCode;
25import org.projectfloodlight.openflow.protocol.OFBarrierReply;
26import org.projectfloodlight.openflow.protocol.OFBarrierRequest;
27import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
28import org.projectfloodlight.openflow.protocol.OFDescStatsRequest;
29import org.projectfloodlight.openflow.protocol.OFEchoReply;
30import org.projectfloodlight.openflow.protocol.OFEchoRequest;
31import org.projectfloodlight.openflow.protocol.OFErrorMsg;
32import org.projectfloodlight.openflow.protocol.OFErrorType;
33import org.projectfloodlight.openflow.protocol.OFExperimenter;
34import org.projectfloodlight.openflow.protocol.OFFactory;
35import org.projectfloodlight.openflow.protocol.OFFeaturesReply;
36import org.projectfloodlight.openflow.protocol.OFFlowModFailedCode;
37import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
38import org.projectfloodlight.openflow.protocol.OFGetConfigReply;
39import org.projectfloodlight.openflow.protocol.OFGetConfigRequest;
40import org.projectfloodlight.openflow.protocol.OFHello;
41import org.projectfloodlight.openflow.protocol.OFHelloElem;
42import org.projectfloodlight.openflow.protocol.OFMessage;
43import org.projectfloodlight.openflow.protocol.OFPacketIn;
44import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply;
45import org.projectfloodlight.openflow.protocol.OFPortDescStatsRequest;
46import org.projectfloodlight.openflow.protocol.OFPortStatus;
47import org.projectfloodlight.openflow.protocol.OFQueueGetConfigReply;
48import org.projectfloodlight.openflow.protocol.OFRoleReply;
49import org.projectfloodlight.openflow.protocol.OFSetConfig;
50import org.projectfloodlight.openflow.protocol.OFStatsReply;
51import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags;
52import org.projectfloodlight.openflow.protocol.OFStatsType;
53import org.projectfloodlight.openflow.protocol.OFType;
54import org.projectfloodlight.openflow.protocol.OFVersion;
55import org.projectfloodlight.openflow.protocol.errormsg.OFBadRequestErrorMsg;
56import org.projectfloodlight.openflow.protocol.errormsg.OFFlowModFailedErrorMsg;
57import org.projectfloodlight.openflow.types.U32;
58import org.slf4j.Logger;
59import org.slf4j.LoggerFactory;
60
61/**
62 * Channel handler deals with the switch connection and dispatches
63 * switch messages to the appropriate locations.
64 */
65class OFChannelHandler extends IdleStateAwareChannelHandler {
66 private static final Logger log = LoggerFactory.getLogger(OFChannelHandler.class);
67 private final Controller controller;
68 private OpenFlowSwitchDriver sw;
69 private long thisdpid; // channelHandler cached value of connected switch id
70 private Channel channel;
71 // State needs to be volatile because the HandshakeTimeoutHandler
72 // needs to check if the handshake is complete
73 private volatile ChannelState state;
74
75 // When a switch with a duplicate dpid is found (i.e we already have a
76 // connected switch with the same dpid), the new switch is immediately
77 // disconnected. At that point netty callsback channelDisconnected() which
78 // proceeds to cleaup switch state - we need to ensure that it does not cleanup
79 // switch state for the older (still connected) switch
80 private volatile Boolean duplicateDpidFound;
81
82 // Temporary storage for switch-features and port-description
83 private OFFeaturesReply featuresReply;
84 private OFPortDescStatsReply portDescReply;
85 // a concurrent ArrayList to temporarily store port status messages
86 // before we are ready to deal with them
87 private final CopyOnWriteArrayList<OFPortStatus> pendingPortStatusMsg;
88
89 //Indicates the openflow version used by this switch
90 protected OFVersion ofVersion;
91 protected OFFactory factory13;
92 protected OFFactory factory10;
93
94 /** transaction Ids to use during handshake. Since only one thread
95 * calls into an OFChannelHandler instance, we don't need atomic.
96 * We will count down
97 */
98 private int handshakeTransactionIds = -1;
99
100 /**
101 * Create a new unconnected OFChannelHandler.
102 * @param controller
103 */
104 OFChannelHandler(Controller controller) {
105 this.controller = controller;
106 this.state = ChannelState.INIT;
107 this.pendingPortStatusMsg = new CopyOnWriteArrayList<OFPortStatus>();
108 factory13 = controller.getOFMessageFactory13();
109 factory10 = controller.getOFMessageFactory10();
110 duplicateDpidFound = Boolean.FALSE;
111 }
112
113
114
115 // XXX S consider if necessary
116 public void disconnectSwitch() {
117 sw.disconnectSwitch();
118 }
119
120
121
122 //*************************
123 // Channel State Machine
124 //*************************
125
126 /**
127 * The state machine for handling the switch/channel state. All state
128 * transitions should happen from within the state machine (and not from other
129 * parts of the code)
130 */
131 enum ChannelState {
132 /**
133 * Initial state before channel is connected.
134 */
135 INIT(false) {
136 @Override
137 void processOFMessage(OFChannelHandler h, OFMessage m)
138 throws IOException, SwitchStateException {
139 illegalMessageReceived(h, m);
140 }
141
142 @Override
143 void processOFError(OFChannelHandler h, OFErrorMsg m)
144 throws IOException {
145 // need to implement since its abstract but it will never
146 // be called
147 }
148
149 @Override
150 void processOFPortStatus(OFChannelHandler h, OFPortStatus m)
151 throws IOException {
152 unhandledMessageReceived(h, m);
153 }
154 },
155
156 /**
157 * We send a OF 1.3 HELLO to the switch and wait for a Hello from the switch.
158 * Once we receive the reply, we decide on OF 1.3 or 1.0 switch - no other
159 * protocol version is accepted.
160 * We send an OFFeaturesRequest depending on the protocol version selected
161 * Next state is WAIT_FEATURES_REPLY
162 */
163 WAIT_HELLO(false) {
164 @Override
165 void processOFHello(OFChannelHandler h, OFHello m)
166 throws IOException {
167 // TODO We could check for the optional bitmap, but for now
168 // we are just checking the version number.
169 if (m.getVersion() == OFVersion.OF_13) {
alshabib09d48be2014-10-03 15:43:33 -0700170 log.debug("Received {} Hello from {}", m.getVersion(),
tom7ef8ff92014-09-17 13:08:06 -0700171 h.channel.getRemoteAddress());
172 h.ofVersion = OFVersion.OF_13;
173 } else if (m.getVersion() == OFVersion.OF_10) {
alshabib09d48be2014-10-03 15:43:33 -0700174 log.debug("Received {} Hello from {} - switching to OF "
tom7ef8ff92014-09-17 13:08:06 -0700175 + "version 1.0", m.getVersion(),
176 h.channel.getRemoteAddress());
177 h.ofVersion = OFVersion.OF_10;
178 } else {
179 log.error("Received Hello of version {} from switch at {}. "
180 + "This controller works with OF1.0 and OF1.3 "
181 + "switches. Disconnecting switch ...",
182 m.getVersion(), h.channel.getRemoteAddress());
183 h.channel.disconnect();
184 return;
185 }
186 h.sendHandshakeFeaturesRequestMessage();
187 h.setState(WAIT_FEATURES_REPLY);
188 }
189 @Override
190 void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m)
191 throws IOException, SwitchStateException {
192 illegalMessageReceived(h, m);
193 }
194 @Override
195 void processOFStatisticsReply(OFChannelHandler h,
196 OFStatsReply m)
197 throws IOException, SwitchStateException {
198 illegalMessageReceived(h, m);
199 }
200 @Override
201 void processOFError(OFChannelHandler h, OFErrorMsg m) {
202 logErrorDisconnect(h, m);
203 }
204
205 @Override
206 void processOFPortStatus(OFChannelHandler h, OFPortStatus m)
207 throws IOException {
208 unhandledMessageReceived(h, m);
209 }
210 },
211
212
213 /**
214 * We are waiting for a features reply message. Once we receive it, the
215 * behavior depends on whether this is a 1.0 or 1.3 switch. For 1.0,
216 * we send a SetConfig request, barrier, and GetConfig request and the
217 * next state is WAIT_CONFIG_REPLY. For 1.3, we send a Port description
218 * request and the next state is WAIT_PORT_DESC_REPLY.
219 */
220 WAIT_FEATURES_REPLY(false) {
221 @Override
222 void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m)
223 throws IOException {
224 h.thisdpid = m.getDatapathId().getLong();
alshabib09d48be2014-10-03 15:43:33 -0700225 log.debug("Received features reply for switch at {} with dpid {}",
tom7ef8ff92014-09-17 13:08:06 -0700226 h.getSwitchInfoString(), h.thisdpid);
227
228 h.featuresReply = m; //temp store
229 if (h.ofVersion == OFVersion.OF_10) {
230 h.sendHandshakeSetConfig();
231 h.setState(WAIT_CONFIG_REPLY);
232 } else {
233 //version is 1.3, must get switchport information
234 h.sendHandshakeOFPortDescRequest();
235 h.setState(WAIT_PORT_DESC_REPLY);
236 }
237 }
238 @Override
239 void processOFStatisticsReply(OFChannelHandler h,
240 OFStatsReply m)
241 throws IOException, SwitchStateException {
242 illegalMessageReceived(h, m);
243 }
244 @Override
245 void processOFError(OFChannelHandler h, OFErrorMsg m) {
246 logErrorDisconnect(h, m);
247 }
248
249 @Override
250 void processOFPortStatus(OFChannelHandler h, OFPortStatus m)
251 throws IOException {
252 unhandledMessageReceived(h, m);
253 }
254 },
255
256 /**
257 * We are waiting for a description of the 1.3 switch ports.
258 * Once received, we send a SetConfig request
259 * Next State is WAIT_CONFIG_REPLY
260 */
261 WAIT_PORT_DESC_REPLY(false) {
262
263 @Override
264 void processOFStatisticsReply(OFChannelHandler h, OFStatsReply m)
265 throws SwitchStateException {
266 // Read port description
267 if (m.getStatsType() != OFStatsType.PORT_DESC) {
268 log.warn("Expecting port description stats but received stats "
269 + "type {} from {}. Ignoring ...", m.getStatsType(),
270 h.channel.getRemoteAddress());
271 return;
272 }
273 if (m.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
274 log.warn("Stats reply indicates more stats from sw {} for "
275 + "port description - not currently handled",
276 h.getSwitchInfoString());
277 }
278 h.portDescReply = (OFPortDescStatsReply) m; // temp store
279 log.info("Received port desc reply for switch at {}",
280 h.getSwitchInfoString());
281 try {
282 h.sendHandshakeSetConfig();
283 } catch (IOException e) {
284 log.error("Unable to send setConfig after PortDescReply. "
285 + "Error: {}", e.getMessage());
286 }
287 h.setState(WAIT_CONFIG_REPLY);
288 }
289
290 @Override
291 void processOFError(OFChannelHandler h, OFErrorMsg m)
292 throws IOException, SwitchStateException {
293 logErrorDisconnect(h, m);
294
295 }
296
297 @Override
298 void processOFPortStatus(OFChannelHandler h, OFPortStatus m)
299 throws IOException, SwitchStateException {
300 unhandledMessageReceived(h, m);
301
302 }
303 },
304
305 /**
306 * We are waiting for a config reply message. Once we receive it
307 * we send a DescriptionStatsRequest to the switch.
308 * Next state: WAIT_DESCRIPTION_STAT_REPLY
309 */
310 WAIT_CONFIG_REPLY(false) {
311 @Override
312 void processOFGetConfigReply(OFChannelHandler h, OFGetConfigReply m)
313 throws IOException {
314 if (m.getMissSendLen() == 0xffff) {
315 log.trace("Config Reply from switch {} confirms "
316 + "miss length set to 0xffff",
317 h.getSwitchInfoString());
318 } else {
319 // FIXME: we can't really deal with switches that don't send
320 // full packets. Shouldn't we drop the connection here?
321 log.warn("Config Reply from switch {} has"
322 + "miss length set to {}",
323 h.getSwitchInfoString(),
324 m.getMissSendLen());
325 }
326 h.sendHandshakeDescriptionStatsRequest();
327 h.setState(WAIT_DESCRIPTION_STAT_REPLY);
328 }
329
330 @Override
331 void processOFBarrierReply(OFChannelHandler h, OFBarrierReply m) {
332 // do nothing;
333 }
334
335 @Override
336 void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m)
337 throws IOException, SwitchStateException {
338 illegalMessageReceived(h, m);
339 }
340 @Override
341 void processOFStatisticsReply(OFChannelHandler h,
342 OFStatsReply m)
343 throws IOException, SwitchStateException {
344 log.error("Received multipart(stats) message sub-type {}",
345 m.getStatsType());
346 illegalMessageReceived(h, m);
347 }
348
349 @Override
350 void processOFError(OFChannelHandler h, OFErrorMsg m) {
351 logErrorDisconnect(h, m);
352 }
353
354 @Override
355 void processOFPortStatus(OFChannelHandler h, OFPortStatus m)
356 throws IOException {
357 h.pendingPortStatusMsg.add(m);
358 }
359 },
360
361
362 /**
363 * We are waiting for a OFDescriptionStat message from the switch.
364 * Once we receive any stat message we try to parse it. If it's not
365 * a description stats message we disconnect. If its the expected
366 * description stats message, we:
367 * - use the switch driver to bind the switch and get an IOFSwitch instance
368 * - setup the IOFSwitch instance
369 * - add switch controller and send the initial role
370 * request to the switch.
371 * Next state: WAIT_INITIAL_ROLE
372 * In the typical case, where switches support role request messages
373 * the next state is where we expect the role reply message.
374 * In the special case that where the switch does not support any kind
375 * of role request messages, we don't send a role message, but we do
376 * request mastership from the registry service. This controller
377 * should become master once we hear back from the registry service.
378 * All following states will have a h.sw instance!
379 */
380 WAIT_DESCRIPTION_STAT_REPLY(false) {
381 @Override
382 void processOFStatisticsReply(OFChannelHandler h, OFStatsReply m)
383 throws SwitchStateException {
384 // Read description, if it has been updated
385 if (m.getStatsType() != OFStatsType.DESC) {
386 log.warn("Expecting Description stats but received stats "
387 + "type {} from {}. Ignoring ...", m.getStatsType(),
388 h.channel.getRemoteAddress());
389 return;
390 }
391 log.info("Received switch description reply from switch at {}",
392 h.channel.getRemoteAddress());
393 OFDescStatsReply drep = (OFDescStatsReply) m;
394 // Here is where we differentiate between different kinds of switches
395 h.sw = h.controller.getOFSwitchInstance(h.thisdpid, drep, h.ofVersion);
396
397 h.sw.setOFVersion(h.ofVersion);
398 h.sw.setFeaturesReply(h.featuresReply);
399 h.sw.setPortDescReply(h.portDescReply);
400 h.sw.setConnected(true);
401 h.sw.setChannel(h.channel);
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700402// boolean success = h.sw.connectSwitch();
403//
404// if (!success) {
405// disconnectDuplicate(h);
406// return;
407// }
tom7ef8ff92014-09-17 13:08:06 -0700408 // set switch information
409
410
411
alshabib09d48be2014-10-03 15:43:33 -0700412 log.debug("Switch {} bound to class {}, description {}",
tom7ef8ff92014-09-17 13:08:06 -0700413 new Object[] {h.sw, h.sw.getClass(), drep });
414 //Put switch in EQUAL mode until we hear back from the global registry
415 //log.debug("Setting new switch {} to EQUAL and sending Role request",
416 // h.sw.getStringId());
417 //h.sw.activateEqualSwitch();
418 //h.setSwitchRole(RoleState.EQUAL);
419
420 h.sw.startDriverHandshake();
alshabib9eab22f2014-10-20 17:17:31 -0700421 if (h.sw.isDriverHandshakeComplete()) {
422 if (!h.sw.connectSwitch()) {
423 disconnectDuplicate(h);
424 }
425 h.setState(ACTIVE);
426 } else {
427 h.setState(WAIT_SWITCH_DRIVER_SUB_HANDSHAKE);
428 }
tom7ef8ff92014-09-17 13:08:06 -0700429
430 }
431
432 @Override
433 void processOFError(OFChannelHandler h, OFErrorMsg m) {
434 logErrorDisconnect(h, m);
435 }
436
437 @Override
438 void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m)
439 throws IOException, SwitchStateException {
440 illegalMessageReceived(h, m);
441 }
442
443 @Override
444 void processOFPortStatus(OFChannelHandler h, OFPortStatus m)
445 throws IOException {
446 h.pendingPortStatusMsg.add(m);
447 }
448 },
449
450
451 /**
452 * We are waiting for the respective switch driver to complete its
453 * configuration. Notice that we do not consider this to be part of the main
454 * switch-controller handshake. But we do consider it as a step that comes
455 * before we declare the switch as available to the controller.
456 * Next State: depends on the role of this controller for this switch - either
457 * MASTER or EQUAL.
458 */
459 WAIT_SWITCH_DRIVER_SUB_HANDSHAKE(true) {
460
461 @Override
462 void processOFError(OFChannelHandler h, OFErrorMsg m)
463 throws IOException {
464 // will never be called. We override processOFMessage
465 }
466
alshabibd7963912014-10-20 14:52:04 -0700467
468
tom7ef8ff92014-09-17 13:08:06 -0700469 @Override
470 void processOFMessage(OFChannelHandler h, OFMessage m)
471 throws IOException, SwitchStateException {
alshabibd7963912014-10-20 14:52:04 -0700472
473 if (h.sw.isDriverHandshakeComplete()) {
474 moveToActive(h);
alshabib9eab22f2014-10-20 17:17:31 -0700475 h.state.processOFMessage(h, m);
476 return;
alshabibd7963912014-10-20 14:52:04 -0700477
478 }
479
tom7ef8ff92014-09-17 13:08:06 -0700480 if (m.getType() == OFType.ECHO_REQUEST) {
481 processOFEchoRequest(h, (OFEchoRequest) m);
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700482 } else if (m.getType() == OFType.ECHO_REPLY) {
483 processOFEchoReply(h, (OFEchoReply) m);
tom7ef8ff92014-09-17 13:08:06 -0700484 } else if (m.getType() == OFType.ROLE_REPLY) {
485 h.sw.handleRole(m);
486 } else if (m.getType() == OFType.ERROR) {
487 if (!h.sw.handleRoleError((OFErrorMsg)m)) {
488 h.sw.processDriverHandshakeMessage(m);
489 if (h.sw.isDriverHandshakeComplete()) {
alshabibd7963912014-10-20 14:52:04 -0700490 moveToActive(h);
tom7ef8ff92014-09-17 13:08:06 -0700491 }
492 }
493 } else {
494 if (m.getType() == OFType.EXPERIMENTER &&
495 ((OFExperimenter) m).getExperimenter() ==
496 RoleManager.NICIRA_EXPERIMENTER) {
497 h.sw.handleNiciraRole(m);
498 } else {
499 h.sw.processDriverHandshakeMessage(m);
500 if (h.sw.isDriverHandshakeComplete()) {
alshabibd7963912014-10-20 14:52:04 -0700501 moveToActive(h);
tom7ef8ff92014-09-17 13:08:06 -0700502 }
503 }
504 }
505 }
506
507 @Override
508 void processOFPortStatus(OFChannelHandler h, OFPortStatus m)
509 throws IOException, SwitchStateException {
510 h.pendingPortStatusMsg.add(m);
511 }
alshabibd7963912014-10-20 14:52:04 -0700512
513 private void moveToActive(OFChannelHandler h) {
514 boolean success = h.sw.connectSwitch();
515 h.setState(ACTIVE);
516 if (!success) {
517 disconnectDuplicate(h);
alshabibd7963912014-10-20 14:52:04 -0700518 }
519 }
520
tom7ef8ff92014-09-17 13:08:06 -0700521 },
522
523
524 /**
525 * This controller is in MASTER role for this switch. We enter this state
526 * after requesting and winning control from the global registry.
527 * The main handshake as well as the switch-driver sub-handshake
528 * is complete at this point.
529 * // XXX S reconsider below
530 * In the (near) future we may deterministically assign controllers to
531 * switches at startup.
532 * We only leave this state if the switch disconnects or
533 * if we send a role request for SLAVE /and/ receive the role reply for
534 * SLAVE.
535 */
536 ACTIVE(true) {
537 @Override
538 void processOFError(OFChannelHandler h, OFErrorMsg m)
539 throws IOException, SwitchStateException {
540 // if we get here, then the error message is for something else
541 if (m.getErrType() == OFErrorType.BAD_REQUEST &&
542 ((OFBadRequestErrorMsg) m).getCode() ==
543 OFBadRequestCode.EPERM) {
544 // We are the master controller and the switch returned
545 // a permission error. This is a likely indicator that
546 // the switch thinks we are slave. Reassert our
547 // role
548 // FIXME: this could be really bad during role transitions
549 // if two controllers are master (even if its only for
550 // a brief period). We might need to see if these errors
551 // persist before we reassert
alshabib339a3d92014-09-26 17:54:32 -0700552
tom7ef8ff92014-09-17 13:08:06 -0700553 h.sw.reassertRole();
554 } else if (m.getErrType() == OFErrorType.FLOW_MOD_FAILED &&
555 ((OFFlowModFailedErrorMsg) m).getCode() ==
556 OFFlowModFailedCode.ALL_TABLES_FULL) {
557 h.sw.setTableFull(true);
558 } else {
559 logError(h, m);
560 }
561 h.dispatchMessage(m);
562 }
563
564 @Override
565 void processOFStatisticsReply(OFChannelHandler h,
566 OFStatsReply m) {
Ayaka Koshibe38594c22014-10-22 13:36:12 -0700567 if (m.getStatsType().equals(OFStatsType.PORT_DESC)) {
568 h.sw.setPortDescReply((OFPortDescStatsReply) m);
569 }
tom7ef8ff92014-09-17 13:08:06 -0700570 h.dispatchMessage(m);
571 }
572
573 @Override
574 void processOFExperimenter(OFChannelHandler h, OFExperimenter m)
575 throws SwitchStateException {
576 h.sw.handleNiciraRole(m);
577 }
578
579 @Override
580 void processOFRoleReply(OFChannelHandler h, OFRoleReply m)
581 throws SwitchStateException {
582 h.sw.handleRole(m);
583 }
584
585 @Override
586 void processOFPortStatus(OFChannelHandler h, OFPortStatus m)
587 throws SwitchStateException {
588 handlePortStatusMessage(h, m, true);
589 h.dispatchMessage(m);
590 }
591
592 @Override
593 void processOFPacketIn(OFChannelHandler h, OFPacketIn m) {
alshabib9eab22f2014-10-20 17:17:31 -0700594// OFPacketOut out =
595// h.sw.factory().buildPacketOut()
596// .setXid(m.getXid())
597// .setBufferId(m.getBufferId()).build();
598// h.sw.sendMsg(out);
tom7ef8ff92014-09-17 13:08:06 -0700599 h.dispatchMessage(m);
600 }
601
602 @Override
603 void processOFFlowRemoved(OFChannelHandler h,
604 OFFlowRemoved m) {
605 h.dispatchMessage(m);
606 }
607
608 @Override
609 void processOFBarrierReply(OFChannelHandler h, OFBarrierReply m) {
610 h.dispatchMessage(m);
611 }
612
Ayaka Koshibee8708e32014-10-22 13:40:18 -0700613 @Override
614 void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m) {
Ayaka Koshibe38594c22014-10-22 13:36:12 -0700615 h.sw.setFeaturesReply(m);
Ayaka Koshibee8708e32014-10-22 13:40:18 -0700616 h.dispatchMessage(m);
617 }
618
tom7ef8ff92014-09-17 13:08:06 -0700619 };
620
621 private final boolean handshakeComplete;
622 ChannelState(boolean handshakeComplete) {
623 this.handshakeComplete = handshakeComplete;
624 }
625
626 /**
627 * Is this a state in which the handshake has completed?
628 * @return true if the handshake is complete
629 */
630 public boolean isHandshakeComplete() {
631 return handshakeComplete;
632 }
633
634 /**
635 * Get a string specifying the switch connection, state, and
636 * message received. To be used as message for SwitchStateException
637 * or log messages
638 * @param h The channel handler (to get switch information_
639 * @param m The OFMessage that has just been received
640 * @param details A string giving more details about the exact nature
641 * of the problem.
642 * @return display string
643 */
644 // needs to be protected because enum members are actually subclasses
645 protected String getSwitchStateMessage(OFChannelHandler h,
646 OFMessage m,
647 String details) {
648 return String.format("Switch: [%s], State: [%s], received: [%s]"
649 + ", details: %s",
650 h.getSwitchInfoString(),
651 this.toString(),
652 m.getType().toString(),
653 details);
654 }
655
656 /**
657 * We have an OFMessage we didn't expect given the current state and
658 * we want to treat this as an error.
659 * We currently throw an exception that will terminate the connection
660 * However, we could be more forgiving
661 * @param h the channel handler that received the message
662 * @param m the message
Jonathan Hart147b2ac2014-10-23 10:03:52 -0700663 * @throws SwitchStateException we always throw the exception
tom7ef8ff92014-09-17 13:08:06 -0700664 */
Jonathan Hart147b2ac2014-10-23 10:03:52 -0700665 // needs to be protected because enum members are actually subclasses
tom7ef8ff92014-09-17 13:08:06 -0700666 protected void illegalMessageReceived(OFChannelHandler h, OFMessage m)
667 throws SwitchStateException {
668 String msg = getSwitchStateMessage(h, m,
669 "Switch should never send this message in the current state");
670 throw new SwitchStateException(msg);
671
672 }
673
674 /**
675 * We have an OFMessage we didn't expect given the current state and
676 * we want to ignore the message.
677 * @param h the channel handler the received the message
678 * @param m the message
679 */
680 protected void unhandledMessageReceived(OFChannelHandler h,
681 OFMessage m) {
682 if (log.isDebugEnabled()) {
683 String msg = getSwitchStateMessage(h, m,
684 "Ignoring unexpected message");
685 log.debug(msg);
686 }
687 }
688
689 /**
690 * Log an OpenFlow error message from a switch.
691 * @param h The switch that sent the error
692 * @param error The error message
693 */
694 protected void logError(OFChannelHandler h, OFErrorMsg error) {
alshabib09d48be2014-10-03 15:43:33 -0700695 log.error("{} from switch {} in state {}",
tom7ef8ff92014-09-17 13:08:06 -0700696 new Object[] {
697 error,
698 h.getSwitchInfoString(),
699 this.toString()});
700 }
701
702 /**
703 * Log an OpenFlow error message from a switch and disconnect the
704 * channel.
705 *
706 * @param h the IO channel for this switch.
707 * @param error The error message
708 */
709 protected void logErrorDisconnect(OFChannelHandler h, OFErrorMsg error) {
710 logError(h, error);
711 h.channel.disconnect();
712 }
713
714 /**
715 * log an error message for a duplicate dpid and disconnect this channel.
716 * @param h the IO channel for this switch.
717 */
718 protected void disconnectDuplicate(OFChannelHandler h) {
719 log.error("Duplicated dpid or incompleted cleanup - "
720 + "disconnecting channel {}", h.getSwitchInfoString());
721 h.duplicateDpidFound = Boolean.TRUE;
722 h.channel.disconnect();
723 }
724
725
726
727 /**
728 * Handles all pending port status messages before a switch is declared
729 * activated in MASTER or EQUAL role. Note that since this handling
730 * precedes the activation (and therefore notification to IOFSwitchListerners)
731 * the changes to ports will already be visible once the switch is
732 * activated. As a result, no notifications are sent out for these
733 * pending portStatus messages.
734 * @param h
735 * @throws SwitchStateException
736 */
737 protected void handlePendingPortStatusMessages(OFChannelHandler h) {
738 try {
739 handlePendingPortStatusMessages(h, 0);
740 } catch (SwitchStateException e) {
741 log.error(e.getMessage());
742 }
743 }
744
745 private void handlePendingPortStatusMessages(OFChannelHandler h, int index)
746 throws SwitchStateException {
747 if (h.sw == null) {
748 String msg = "State machine error: switch is null. Should never " +
749 "happen";
750 throw new SwitchStateException(msg);
751 }
752 ArrayList<OFPortStatus> temp = new ArrayList<OFPortStatus>();
753 for (OFPortStatus ps: h.pendingPortStatusMsg) {
754 temp.add(ps);
755 handlePortStatusMessage(h, ps, false);
756 }
757 temp.clear();
758 // expensive but ok - we don't expect too many port-status messages
759 // note that we cannot use clear(), because of the reasons below
760 h.pendingPortStatusMsg.removeAll(temp);
761 // the iterator above takes a snapshot of the list - so while we were
762 // dealing with the pending port-status messages, we could have received
763 // newer ones. Handle them recursively, but break the recursion after
764 // five steps to avoid an attack.
765 if (!h.pendingPortStatusMsg.isEmpty() && ++index < 5) {
766 handlePendingPortStatusMessages(h, index);
767 }
768 }
769
770 /**
771 * Handle a port status message.
772 *
773 * Handle a port status message by updating the port maps in the
774 * IOFSwitch instance and notifying Controller about the change so
775 * it can dispatch a switch update.
776 *
777 * @param h The OFChannelHhandler that received the message
778 * @param m The PortStatus message we received
779 * @param doNotify if true switch port changed events will be
780 * dispatched
781 * @throws SwitchStateException
782 *
783 */
784 protected void handlePortStatusMessage(OFChannelHandler h, OFPortStatus m,
785 boolean doNotify) throws SwitchStateException {
786 if (h.sw == null) {
787 String msg = getSwitchStateMessage(h, m,
788 "State machine error: switch is null. Should never " +
789 "happen");
790 throw new SwitchStateException(msg);
791 }
792
793 h.sw.handleMessage(m);
794 }
795
796
797 /**
798 * Process an OF message received on the channel and
799 * update state accordingly.
800 *
801 * The main "event" of the state machine. Process the received message,
802 * send follow up message if required and update state if required.
803 *
804 * Switches on the message type and calls more specific event handlers
805 * for each individual OF message type. If we receive a message that
806 * is supposed to be sent from a controller to a switch we throw
807 * a SwitchStateExeption.
808 *
809 * The more specific handlers can also throw SwitchStateExceptions
810 *
811 * @param h The OFChannelHandler that received the message
812 * @param m The message we received.
813 * @throws SwitchStateException
814 * @throws IOException
815 */
816 void processOFMessage(OFChannelHandler h, OFMessage m)
817 throws IOException, SwitchStateException {
818 switch(m.getType()) {
819 case HELLO:
820 processOFHello(h, (OFHello) m);
821 break;
822 case BARRIER_REPLY:
823 processOFBarrierReply(h, (OFBarrierReply) m);
824 break;
825 case ECHO_REPLY:
826 processOFEchoReply(h, (OFEchoReply) m);
827 break;
828 case ECHO_REQUEST:
829 processOFEchoRequest(h, (OFEchoRequest) m);
830 break;
831 case ERROR:
832 processOFError(h, (OFErrorMsg) m);
833 break;
834 case FEATURES_REPLY:
835 processOFFeaturesReply(h, (OFFeaturesReply) m);
836 break;
837 case FLOW_REMOVED:
838 processOFFlowRemoved(h, (OFFlowRemoved) m);
839 break;
840 case GET_CONFIG_REPLY:
841 processOFGetConfigReply(h, (OFGetConfigReply) m);
842 break;
843 case PACKET_IN:
844 processOFPacketIn(h, (OFPacketIn) m);
845 break;
846 case PORT_STATUS:
847 processOFPortStatus(h, (OFPortStatus) m);
848 break;
849 case QUEUE_GET_CONFIG_REPLY:
850 processOFQueueGetConfigReply(h, (OFQueueGetConfigReply) m);
851 break;
852 case STATS_REPLY: // multipart_reply in 1.3
853 processOFStatisticsReply(h, (OFStatsReply) m);
854 break;
855 case EXPERIMENTER:
856 processOFExperimenter(h, (OFExperimenter) m);
857 break;
858 case ROLE_REPLY:
859 processOFRoleReply(h, (OFRoleReply) m);
860 break;
861 case GET_ASYNC_REPLY:
862 processOFGetAsyncReply(h, (OFAsyncGetReply) m);
863 break;
864
865 // The following messages are sent to switches. The controller
866 // should never receive them
867 case SET_CONFIG:
868 case GET_CONFIG_REQUEST:
869 case PACKET_OUT:
870 case PORT_MOD:
871 case QUEUE_GET_CONFIG_REQUEST:
872 case BARRIER_REQUEST:
873 case STATS_REQUEST: // multipart request in 1.3
874 case FEATURES_REQUEST:
875 case FLOW_MOD:
876 case GROUP_MOD:
877 case TABLE_MOD:
878 case GET_ASYNC_REQUEST:
879 case SET_ASYNC:
880 case METER_MOD:
881 default:
882 illegalMessageReceived(h, m);
883 break;
884 }
885 }
886
887 /*-----------------------------------------------------------------
888 * Default implementation for message handlers in any state.
889 *
890 * Individual states must override these if they want a behavior
891 * that differs from the default.
892 *
893 * In general, these handlers simply ignore the message and do
894 * nothing.
895 *
896 * There are some exceptions though, since some messages really
897 * are handled the same way in every state (e.g., ECHO_REQUST) or
898 * that are only valid in a single state (e.g., HELLO, GET_CONFIG_REPLY
899 -----------------------------------------------------------------*/
900
901 void processOFHello(OFChannelHandler h, OFHello m)
902 throws IOException, SwitchStateException {
903 // we only expect hello in the WAIT_HELLO state
904 illegalMessageReceived(h, m);
905 }
906
907 void processOFBarrierReply(OFChannelHandler h, OFBarrierReply m)
908 throws IOException {
909 // Silently ignore.
910 }
911
912 void processOFEchoRequest(OFChannelHandler h, OFEchoRequest m)
913 throws IOException {
914 if (h.ofVersion == null) {
915 log.error("No OF version set for {}. Not sending Echo REPLY",
916 h.channel.getRemoteAddress());
917 return;
918 }
919 OFFactory factory = (h.ofVersion == OFVersion.OF_13) ?
920 h.controller.getOFMessageFactory13() : h.controller.getOFMessageFactory10();
921 OFEchoReply reply = factory
922 .buildEchoReply()
923 .setXid(m.getXid())
924 .setData(m.getData())
925 .build();
926 h.channel.write(Collections.singletonList(reply));
927 }
928
929 void processOFEchoReply(OFChannelHandler h, OFEchoReply m)
930 throws IOException {
931 // Do nothing with EchoReplies !!
932 }
933
934 // no default implementation for OFError
935 // every state must override it
936 abstract void processOFError(OFChannelHandler h, OFErrorMsg m)
937 throws IOException, SwitchStateException;
938
939
940 void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m)
941 throws IOException, SwitchStateException {
942 unhandledMessageReceived(h, m);
943 }
944
945 void processOFFlowRemoved(OFChannelHandler h, OFFlowRemoved m)
946 throws IOException {
947 unhandledMessageReceived(h, m);
948 }
949
950 void processOFGetConfigReply(OFChannelHandler h, OFGetConfigReply m)
951 throws IOException, SwitchStateException {
952 // we only expect config replies in the WAIT_CONFIG_REPLY state
953 illegalMessageReceived(h, m);
954 }
955
956 void processOFPacketIn(OFChannelHandler h, OFPacketIn m)
957 throws IOException {
958 unhandledMessageReceived(h, m);
959 }
960
961 // no default implementation. Every state needs to handle it.
962 abstract void processOFPortStatus(OFChannelHandler h, OFPortStatus m)
963 throws IOException, SwitchStateException;
964
965 void processOFQueueGetConfigReply(OFChannelHandler h,
966 OFQueueGetConfigReply m)
967 throws IOException {
968 unhandledMessageReceived(h, m);
969 }
970
971 void processOFStatisticsReply(OFChannelHandler h, OFStatsReply m)
972 throws IOException, SwitchStateException {
973 unhandledMessageReceived(h, m);
974 }
975
976 void processOFExperimenter(OFChannelHandler h, OFExperimenter m)
977 throws IOException, SwitchStateException {
978 // TODO: it might make sense to parse the vendor message here
979 // into the known vendor messages we support and then call more
980 // specific event handlers
981 unhandledMessageReceived(h, m);
982 }
983
984 void processOFRoleReply(OFChannelHandler h, OFRoleReply m)
985 throws SwitchStateException, IOException {
986 unhandledMessageReceived(h, m);
987 }
988
989 void processOFGetAsyncReply(OFChannelHandler h,
990 OFAsyncGetReply m) {
991 unhandledMessageReceived(h, m);
992 }
993
994 }
995
996
997
998 //*************************
999 // Channel handler methods
1000 //*************************
1001
1002 @Override
1003 public void channelConnected(ChannelHandlerContext ctx,
1004 ChannelStateEvent e) throws Exception {
1005 channel = e.getChannel();
1006 log.info("New switch connection from {}",
1007 channel.getRemoteAddress());
1008 sendHandshakeHelloMessage();
1009 setState(ChannelState.WAIT_HELLO);
1010 }
1011
1012 @Override
1013 public void channelDisconnected(ChannelHandlerContext ctx,
1014 ChannelStateEvent e) throws Exception {
1015 log.info("Switch disconnected callback for sw:{}. Cleaning up ...",
1016 getSwitchInfoString());
1017 if (thisdpid != 0) {
1018 if (!duplicateDpidFound) {
1019 // if the disconnected switch (on this ChannelHandler)
1020 // was not one with a duplicate-dpid, it is safe to remove all
1021 // state for it at the controller. Notice that if the disconnected
1022 // switch was a duplicate-dpid, calling the method below would clear
1023 // all state for the original switch (with the same dpid),
1024 // which we obviously don't want.
Yuta HIGUCHI17679472014-10-09 21:53:14 -07001025 log.info("{}:removal called", getSwitchInfoString());
Jonathan Hart147b2ac2014-10-23 10:03:52 -07001026 if (sw != null) {
1027 sw.removeConnectedSwitch();
1028 }
tom7ef8ff92014-09-17 13:08:06 -07001029 } else {
1030 // A duplicate was disconnected on this ChannelHandler,
1031 // this is the same switch reconnecting, but the original state was
1032 // not cleaned up - XXX check liveness of original ChannelHandler
Yuta HIGUCHI17679472014-10-09 21:53:14 -07001033 log.info("{}:duplicate found", getSwitchInfoString());
tom7ef8ff92014-09-17 13:08:06 -07001034 duplicateDpidFound = Boolean.FALSE;
1035 }
1036 } else {
1037 log.warn("no dpid in channelHandler registered for "
1038 + "disconnected switch {}", getSwitchInfoString());
1039 }
1040 }
1041
1042 @Override
1043 public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
1044 throws Exception {
1045 if (e.getCause() instanceof ReadTimeoutException) {
1046 // switch timeout
1047 log.error("Disconnecting switch {} due to read timeout",
1048 getSwitchInfoString());
1049 ctx.getChannel().close();
1050 } else if (e.getCause() instanceof HandshakeTimeoutException) {
1051 log.error("Disconnecting switch {}: failed to complete handshake",
1052 getSwitchInfoString());
1053 ctx.getChannel().close();
1054 } else if (e.getCause() instanceof ClosedChannelException) {
1055 log.debug("Channel for sw {} already closed", getSwitchInfoString());
1056 } else if (e.getCause() instanceof IOException) {
1057 log.error("Disconnecting switch {} due to IO Error: {}",
1058 getSwitchInfoString(), e.getCause().getMessage());
1059 if (log.isDebugEnabled()) {
1060 // still print stack trace if debug is enabled
1061 log.debug("StackTrace for previous Exception: ", e.getCause());
1062 }
1063 ctx.getChannel().close();
1064 } else if (e.getCause() instanceof SwitchStateException) {
1065 log.error("Disconnecting switch {} due to switch state error: {}",
1066 getSwitchInfoString(), e.getCause().getMessage());
1067 if (log.isDebugEnabled()) {
1068 // still print stack trace if debug is enabled
1069 log.debug("StackTrace for previous Exception: ", e.getCause());
1070 }
1071 ctx.getChannel().close();
1072 } else if (e.getCause() instanceof OFParseError) {
1073 log.error("Disconnecting switch "
1074 + getSwitchInfoString() +
1075 " due to message parse failure",
1076 e.getCause());
1077 ctx.getChannel().close();
1078 } else if (e.getCause() instanceof RejectedExecutionException) {
1079 log.warn("Could not process message: queue full");
1080 } else {
1081 log.error("Error while processing message from switch "
1082 + getSwitchInfoString()
1083 + "state " + this.state, e.getCause());
1084 ctx.getChannel().close();
1085 }
1086 }
1087
1088 @Override
1089 public String toString() {
1090 return getSwitchInfoString();
1091 }
1092
1093 @Override
1094 public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e)
1095 throws Exception {
1096 OFFactory factory = (ofVersion == OFVersion.OF_13) ? factory13 : factory10;
1097 OFMessage m = factory.buildEchoRequest().build();
alshabib09d48be2014-10-03 15:43:33 -07001098 log.debug("Sending Echo Request on idle channel: {}",
tom7ef8ff92014-09-17 13:08:06 -07001099 e.getChannel().getPipeline().getLast().toString());
1100 e.getChannel().write(Collections.singletonList(m));
1101 // XXX S some problems here -- echo request has no transaction id, and
1102 // echo reply is not correlated to the echo request.
1103 }
1104
1105 @Override
1106 public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
1107 throws Exception {
1108 if (e.getMessage() instanceof List) {
1109 @SuppressWarnings("unchecked")
1110 List<OFMessage> msglist = (List<OFMessage>) e.getMessage();
1111
1112
1113 for (OFMessage ofm : msglist) {
1114 // Do the actual packet processing
1115 state.processOFMessage(this, ofm);
1116 }
1117 } else {
1118 state.processOFMessage(this, (OFMessage) e.getMessage());
1119 }
1120 }
1121
1122
1123
1124 //*************************
1125 // Channel utility methods
1126 //*************************
1127
1128 /**
1129 * Is this a state in which the handshake has completed?
1130 * @return true if the handshake is complete
1131 */
1132 public boolean isHandshakeComplete() {
1133 return this.state.isHandshakeComplete();
1134 }
1135
1136 private void dispatchMessage(OFMessage m) {
1137 sw.handleMessage(m);
1138 }
1139
1140 /**
1141 * Return a string describing this switch based on the already available
1142 * information (DPID and/or remote socket).
1143 * @return display string
1144 */
1145 private String getSwitchInfoString() {
1146 if (sw != null) {
1147 return sw.toString();
1148 }
1149 String channelString;
1150 if (channel == null || channel.getRemoteAddress() == null) {
1151 channelString = "?";
1152 } else {
1153 channelString = channel.getRemoteAddress().toString();
1154 }
1155 String dpidString;
1156 if (featuresReply == null) {
1157 dpidString = "?";
1158 } else {
1159 dpidString = featuresReply.getDatapathId().toString();
1160 }
1161 return String.format("[%s DPID[%s]]", channelString, dpidString);
1162 }
1163
1164 /**
1165 * Update the channels state. Only called from the state machine.
1166 * TODO: enforce restricted state transitions
1167 * @param state
1168 */
1169 private void setState(ChannelState state) {
1170 this.state = state;
1171 }
1172
1173 /**
1174 * Send hello message to the switch using the handshake transactions ids.
1175 * @throws IOException
1176 */
1177 private void sendHandshakeHelloMessage() throws IOException {
1178 // The OF protocol requires us to start things off by sending the highest
1179 // version of the protocol supported.
1180
1181 // bitmap represents OF1.0 (ofp_version=0x01) and OF1.3 (ofp_version=0x04)
1182 // see Sec. 7.5.1 of the OF1.3.4 spec
1183 U32 bitmap = U32.ofRaw(0x00000012);
1184 OFHelloElem hem = factory13.buildHelloElemVersionbitmap()
1185 .setBitmaps(Collections.singletonList(bitmap))
1186 .build();
1187 OFMessage.Builder mb = factory13.buildHello()
1188 .setXid(this.handshakeTransactionIds--)
1189 .setElements(Collections.singletonList(hem));
1190 log.info("Sending OF_13 Hello to {}", channel.getRemoteAddress());
1191 channel.write(Collections.singletonList(mb.build()));
1192 }
1193
1194 /**
1195 * Send featuresRequest msg to the switch using the handshake transactions ids.
1196 * @throws IOException
1197 */
1198 private void sendHandshakeFeaturesRequestMessage() throws IOException {
1199 OFFactory factory = (ofVersion == OFVersion.OF_13) ? factory13 : factory10;
1200 OFMessage m = factory.buildFeaturesRequest()
1201 .setXid(this.handshakeTransactionIds--)
1202 .build();
1203 channel.write(Collections.singletonList(m));
1204 }
1205
1206 /**
1207 * Send the configuration requests to tell the switch we want full
1208 * packets.
1209 * @throws IOException
1210 */
1211 private void sendHandshakeSetConfig() throws IOException {
1212 OFFactory factory = (ofVersion == OFVersion.OF_13) ? factory13 : factory10;
1213 //log.debug("Sending CONFIG_REQUEST to {}", channel.getRemoteAddress());
1214 List<OFMessage> msglist = new ArrayList<OFMessage>(3);
1215
1216 // Ensure we receive the full packet via PacketIn
1217 // FIXME: We don't set the reassembly flags.
1218 OFSetConfig sc = factory
1219 .buildSetConfig()
1220 .setMissSendLen((short) 0xffff)
1221 .setXid(this.handshakeTransactionIds--)
1222 .build();
1223 msglist.add(sc);
1224
1225 // Barrier
1226 OFBarrierRequest br = factory
1227 .buildBarrierRequest()
1228 .setXid(this.handshakeTransactionIds--)
1229 .build();
1230 msglist.add(br);
1231
1232 // Verify (need barrier?)
1233 OFGetConfigRequest gcr = factory
1234 .buildGetConfigRequest()
1235 .setXid(this.handshakeTransactionIds--)
1236 .build();
1237 msglist.add(gcr);
1238 channel.write(msglist);
1239 }
1240
1241 /**
1242 * send a description state request.
1243 * @throws IOException
1244 */
1245 private void sendHandshakeDescriptionStatsRequest() throws IOException {
1246 // Get Description to set switch-specific flags
1247 OFFactory factory = (ofVersion == OFVersion.OF_13) ? factory13 : factory10;
1248 OFDescStatsRequest dreq = factory
1249 .buildDescStatsRequest()
1250 .setXid(handshakeTransactionIds--)
1251 .build();
1252 channel.write(Collections.singletonList(dreq));
1253 }
1254
1255 private void sendHandshakeOFPortDescRequest() throws IOException {
1256 // Get port description for 1.3 switch
1257 OFPortDescStatsRequest preq = factory13
1258 .buildPortDescStatsRequest()
1259 .setXid(handshakeTransactionIds--)
1260 .build();
1261 channel.write(Collections.singletonList(preq));
1262 }
1263
1264 ChannelState getStateForTesting() {
1265 return state;
1266 }
1267
1268}