2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.openflow.md.core;
11 import static org.junit.Assert.assertNotNull;
13 import java.math.BigInteger;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.HashMap;
17 import java.util.List;
19 import java.util.Stack;
20 import java.util.concurrent.ScheduledThreadPoolExecutor;
21 import org.junit.After;
22 import org.junit.Assert;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.ArgumentCaptor;
27 import org.mockito.Matchers;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.runners.MockitoJUnitRunner;
31 import org.opendaylight.openflowplugin.api.OFConstants;
32 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
33 import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
34 import org.opendaylight.openflowplugin.openflow.md.core.plan.ConnectionAdapterStackImpl;
35 import org.opendaylight.openflowplugin.openflow.md.core.plan.EventFactory;
36 import org.opendaylight.openflowplugin.openflow.md.core.plan.SwitchTestEvent;
37 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
38 import org.opendaylight.openflowplugin.openflow.md.queue.PopListener;
39 import org.opendaylight.openflowplugin.openflow.md.queue.QueueProcessorLightImpl;
40 import org.opendaylight.openflowplugin.api.statistics.MessageSpy;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder;
58 import org.opendaylight.yangtools.yang.binding.DataContainer;
59 import org.opendaylight.yangtools.yang.binding.DataObject;
60 import org.slf4j.Logger;
61 import org.slf4j.LoggerFactory;
63 @RunWith(MockitoJUnitRunner.class)
64 public class ConnectionConductorImplTest {
66 protected static final Logger LOG = LoggerFactory
67 .getLogger(ConnectionConductorImplTest.class);
72 private final int maxProcessingTimeout = 500;
74 protected ConnectionAdapterStackImpl adapter;
75 private ConnectionConductorImpl connectionConductor;
76 private MDController controller;
77 private Stack<SwitchTestEvent> eventPlan;
79 private Thread libSimulation;
80 private ScheduledThreadPoolExecutor pool = new ScheduledThreadPoolExecutor(
83 protected QueueProcessorLightImpl queueProcessor;
85 private PopListener<DataObject> popListener;
87 private int experimenterMessageCounter;
88 private int packetinMessageCounter;
89 private int flowremovedMessageCounter;
90 private int portstatusAddMessageCounter;
91 private int portstatusDeleteMessageCounter;
92 private int portstatusModifyMessageCounter;
93 private int errorMessageCounter;
96 private ErrorHandlerSimpleImpl errorHandler;
98 private int expectedErrors = 0;
100 private MessageSpy<DataContainer> messageSpy;
102 public void incrExperimenterMessageCounter() {
103 this.experimenterMessageCounter++;
106 public void incrPacketinMessageCounter() {
107 this.packetinMessageCounter++;
110 public void incrFlowremovedMessageCounter() {
111 this.flowremovedMessageCounter++;
114 public void incrPortstatusAddMessageCounter() {
115 this.portstatusAddMessageCounter++;
118 public void incrPortstatusDeleteMessageCounter() {
119 this.portstatusDeleteMessageCounter++;
122 public void incrPortstatusModifyMessageCounter() {
123 this.portstatusModifyMessageCounter++;
126 public void incrErrorMessageCounter() {
127 this.errorMessageCounter++;
132 * Test for ConnectionConductorFactory#createConductor
134 public void testCreateConductor() {
135 ConnectionConductor connectionConductor = ConnectionConductorFactory.createConductor(adapter, queueProcessor);
136 assertNotNull(connectionConductor);
140 * @throws java.lang.Exception
143 public void setUp() throws Exception {
144 adapter = new ConnectionAdapterStackImpl();
146 popListener = new PopListenerCountingImpl<>();
148 controller = new MDController();
150 controller.getMessageTranslators().putAll(assembleTranslatorMapping());
152 queueProcessor = new QueueProcessorLightImpl();
153 queueProcessor.setMessageSpy(messageSpy);
154 queueProcessor.setPopListenersMapping(assemblePopListenerMapping());
155 queueProcessor.setTranslatorMapping(controller.getMessageTranslators());
156 queueProcessor.init();
158 connectionConductor = new ConnectionConductorImpl(adapter);
159 connectionConductor.setQueueProcessor(queueProcessor);
160 connectionConductor.setErrorHandler(errorHandler);
161 connectionConductor.init();
162 eventPlan = new Stack<>();
163 adapter.setEventPlan(eventPlan);
164 adapter.setProceedTimeout(5000L);
165 adapter.checkListeners();
171 private Map<Class<? extends DataObject>, Collection<PopListener<DataObject>>> assemblePopListenerMapping() {
172 Map<Class<? extends DataObject>, Collection<PopListener<DataObject>>> mapping = new HashMap<>();
173 Collection<PopListener<DataObject>> popListenerBag = new ArrayList<>();
174 popListenerBag.add(popListener);
175 //TODO: add testing registered types
176 mapping.put(DataObject.class, popListenerBag);
181 * @throws java.lang.Exception
184 public void tearDown() throws Exception {
185 if (libSimulation != null) {
186 libSimulation.join();
188 queueProcessor.shutdown();
189 connectionConductor.shutdownPool();
191 for (Exception problem : adapter.getOccuredExceptions()) {
192 LOG.error("during simulation on adapter side: "
193 + problem.getMessage());
195 Assert.assertEquals(0, adapter.getOccuredExceptions().size());
197 if (LOG.isDebugEnabled()) {
198 if (eventPlan.size() > 0) {
199 LOG.debug("eventPlan size: " + eventPlan.size());
200 for (SwitchTestEvent event : eventPlan) {
201 LOG.debug(" # EVENT:: " + event.toString());
205 Assert.assertTrue("plan is not finished", eventPlan.isEmpty());
209 // logging errors if occurred
210 ArgumentCaptor<Throwable> errorCaptor = ArgumentCaptor.forClass(Throwable.class);
211 Mockito.verify(errorHandler, Mockito.atMost(1)).handleException(
212 errorCaptor.capture(), Matchers.any(SessionContext.class));
213 for (Throwable problem : errorCaptor.getAllValues()) {
214 LOG.warn(problem.getMessage(), problem);
217 Mockito.verify(errorHandler, Mockito.times(expectedErrors)).handleException(
218 Matchers.any(Throwable.class), Matchers.any(SessionContext.class));
223 * {@link org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductorImpl#onEchoRequestMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage)}
229 public void testOnEchoRequestMessage() throws Exception {
230 simulateV13PostHandshakeState(connectionConductor);
232 eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
233 EventFactory.DEFAULT_VERSION, new EchoRequestMessageBuilder()));
235 EventFactory.createDefaultWaitForRpcEvent(42, "echoReply"));
240 * Test of handshake, covering version negotiation and features.
241 * Switch delivers first helloMessage with default version.
246 public void testHandshake1() throws Exception {
247 eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
248 EventFactory.DEFAULT_VERSION, new HelloMessageBuilder()));
249 eventPlan.add(0, EventFactory.createDefaultWaitForAllEvent(
250 EventFactory.createDefaultWaitForRpcEvent(43, "helloReply"),
251 EventFactory.createDefaultWaitForRpcEvent(44, "getFeatures")));
252 eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(44,
253 EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
256 eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(i++, "setConfig"));
257 eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(i++, "multipartRequestInput"));
258 eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(i++, "multipartRequestInput"));
259 eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(i++, "multipartRequestInput"));
260 eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(i++, "multipartRequestInput"));
263 Assert.assertEquals(ConnectionConductor.CONDUCTOR_STATE.WORKING,
264 connectionConductor.getConductorState());
265 Assert.assertEquals((short) 0x04, connectionConductor.getVersion()
270 * Test of handshake, covering version negotiation and features.
271 * Controller sends first helloMessage with default version
276 public void testHandshake1SwitchStarts() throws Exception {
277 eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
278 eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"));
279 eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
280 EventFactory.DEFAULT_VERSION, new HelloMessageBuilder()));
281 eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(43, "getFeatures"));
282 eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(43,
283 EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
286 eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(i++, "setConfig"));
287 eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(i++, "multipartRequestInput"));
288 eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(i++, "multipartRequestInput"));
289 eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(i++, "multipartRequestInput"));
290 eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(i++, "multipartRequestInput"));
294 Assert.assertEquals(ConnectionConductor.CONDUCTOR_STATE.WORKING,
295 connectionConductor.getConductorState());
296 Assert.assertEquals((short) 0x04, connectionConductor.getVersion()
301 * Test of handshake, covering version negotiation and features.
302 * Switch delivers first helloMessage with version 0x05
303 * and negotiates following versions: 0x03, 0x01
308 public void testHandshake2() throws Exception {
309 connectionConductor.setBitmapNegotiationEnable(false);
310 eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
311 (short) 0x05, new HelloMessageBuilder()));
313 EventFactory.createDefaultWaitForRpcEvent(43, "helloReply"));
314 eventPlan.add(0, EventFactory.createDefaultNotificationEvent(43L,
315 (short) 0x03, new HelloMessageBuilder()));
317 EventFactory.createDefaultWaitForRpcEvent(44, "helloReply"));
318 eventPlan.add(0, EventFactory.createDefaultNotificationEvent(44L,
319 (short) 0x01, new HelloMessageBuilder()));
321 EventFactory.createDefaultWaitForRpcEvent(45, "getFeatures"));
323 eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(45,
324 EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
326 eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(1, "multipartRequestInput"));
330 Assert.assertEquals(ConnectionConductor.CONDUCTOR_STATE.WORKING,
331 connectionConductor.getConductorState());
332 Assert.assertEquals((short) 0x01, connectionConductor.getVersion()
337 * Test of handshake, covering version negotiation and features.
338 * Controller sends first helloMessage with default version
339 * and switch negotiates following versions: 0x05, 0x03, 0x01
344 public void testHandshake2SwitchStarts() throws Exception {
345 connectionConductor.setBitmapNegotiationEnable(false);
346 eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
348 EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"));
349 eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
350 (short) 0x05, new HelloMessageBuilder()));
351 eventPlan.add(0, EventFactory.createDefaultNotificationEvent(43L,
352 (short) 0x03, new HelloMessageBuilder()));
354 EventFactory.createDefaultWaitForRpcEvent(44, "helloReply"));
355 eventPlan.add(0, EventFactory.createDefaultNotificationEvent(44L,
356 (short) 0x01, new HelloMessageBuilder()));
358 EventFactory.createDefaultWaitForRpcEvent(45, "getFeatures"));
360 eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(45,
361 EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
363 eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(1, "multipartRequestInput"));
367 Assert.assertEquals(ConnectionConductor.CONDUCTOR_STATE.WORKING,
368 connectionConductor.getConductorState());
369 Assert.assertEquals((short) 0x01, connectionConductor.getVersion()
375 * {@link org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductorImpl#onFlowRemovedMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage)}
378 * @throws InterruptedException
381 public void testOnFlowRemovedMessage() throws InterruptedException {
382 IMDMessageTranslator<OfHeader, List<DataObject>> objFms = new FlowRemovedMessageService();
383 controller.addMessageTranslator(FlowRemovedMessage.class, 4, objFms);
385 simulateV13PostHandshakeState(connectionConductor);
387 // Now send Flow Removed messages
388 FlowRemovedMessageBuilder builder1 = new FlowRemovedMessageBuilder();
389 builder1.setVersion((short) 4);
391 connectionConductor.onFlowRemovedMessage(builder1.build());
392 synchronized (popListener) {
393 LOG.debug("about to wait for popListener");
394 popListener.wait(maxProcessingTimeout);
396 Assert.assertEquals(1, flowremovedMessageCounter);
398 connectionConductor.onFlowRemovedMessage(builder1.build());
399 synchronized (popListener) {
400 popListener.wait(maxProcessingTimeout);
402 Assert.assertEquals(2, flowremovedMessageCounter);
407 * {@link org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductorImpl#onMultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage)}
411 public void testOnMultipartReplyMessage() {
412 // fail("Not yet implemented");
418 * {@link org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductorImpl#onPacketInMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage)}
421 * @throws InterruptedException
424 public void testOnPacketInMessage() throws InterruptedException {
425 IMDMessageTranslator<OfHeader, List<DataObject>> objPms = new PacketInMessageService();
426 controller.addMessageTranslator(PacketInMessage.class, 4, objPms);
428 simulateV13PostHandshakeState(connectionConductor);
431 PacketInMessageBuilder builder1 = new PacketInMessageBuilder();
432 builder1.setVersion((short) 4);
433 builder1.setBufferId((long) 1);
434 connectionConductor.onPacketInMessage(builder1.build());
435 synchronized (popListener) {
436 popListener.wait(maxProcessingTimeout);
438 Assert.assertEquals(1, packetinMessageCounter);
439 builder1.setBufferId((long) 2);
440 connectionConductor.onPacketInMessage(builder1.build());
441 synchronized (popListener) {
442 popListener.wait(maxProcessingTimeout);
444 Assert.assertEquals(2, packetinMessageCounter);
449 * {@link org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductorImpl#onPortStatusMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)}
452 * @throws InterruptedException
455 public void testOnPortStatusMessage() throws InterruptedException {
456 IMDMessageTranslator<OfHeader, List<DataObject>> objPSms = new PortStatusMessageService();
457 controller.addMessageTranslator(PortStatusMessage.class, 4, objPSms);
459 simulateV13PostHandshakeState(connectionConductor);
461 // Send Port Status messages
462 PortStatusMessageBuilder builder1 = new PortStatusMessageBuilder();
463 builder1.setVersion((short) 4);
464 PortFeatures features = new PortFeatures(true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false);
465 builder1.setPortNo(90L).setReason(PortReason.OFPPRADD).setCurrentFeatures(features);
466 connectionConductor.onPortStatusMessage(builder1.build());
467 synchronized (popListener) {
468 popListener.wait(maxProcessingTimeout);
470 Assert.assertEquals(1, portstatusAddMessageCounter);
471 builder1.setPortNo(90L).setReason(PortReason.OFPPRMODIFY).setCurrentFeatures(features);
472 connectionConductor.onPortStatusMessage(builder1.build());
473 synchronized (popListener) {
474 popListener.wait(maxProcessingTimeout);
476 Assert.assertEquals(1, portstatusModifyMessageCounter);
477 builder1.setPortNo(90L).setReason(PortReason.OFPPRDELETE).setCurrentFeatures(features);
478 connectionConductor.onPortStatusMessage(builder1.build());
479 synchronized (popListener) {
480 popListener.wait(maxProcessingTimeout);
482 Assert.assertEquals(1, portstatusDeleteMessageCounter);
486 * @throws InterruptedException
488 private void executeLater() throws InterruptedException {
493 * @throws InterruptedException
495 private void executeNow() throws InterruptedException {
497 connectionConductor.shutdownPool();
501 * @throws InterruptedException
503 private void execute(boolean join) throws InterruptedException {
504 libSimulation = new Thread(adapter, "junit-adapter");
505 libSimulation.start();
507 libSimulation.join();
511 private static GetFeaturesOutputBuilder getFeatureResponseMsg() {
512 GetFeaturesOutputBuilder getFeaturesOutputBuilder = new GetFeaturesOutputBuilder();
513 getFeaturesOutputBuilder.setDatapathId(new BigInteger("102030405060"));
514 getFeaturesOutputBuilder.setAuxiliaryId((short) 0);
515 getFeaturesOutputBuilder.setBuffers(4L);
516 getFeaturesOutputBuilder.setReserved(0L);
517 getFeaturesOutputBuilder.setTables((short) 2);
518 getFeaturesOutputBuilder.setCapabilities(createCapabilities(84));
520 return getFeaturesOutputBuilder;
526 private static Capabilities createCapabilities(long input) {
527 final Boolean FLOW_STATS = (input & (1 << 0)) != 0;
528 final Boolean TABLE_STATS = (input & (1 << 1)) != 0;
529 final Boolean PORT_STATS = (input & (1 << 2)) != 0;
530 final Boolean GROUP_STATS = (input & (1 << 3)) != 0;
531 final Boolean IP_REASM = (input & (1 << 5)) != 0;
532 final Boolean QUEUE_STATS = (input & (1 << 6)) != 0;
533 final Boolean PORT_BLOCKED = (input & (1 << 8)) != 0;
534 Capabilities capabilities = new Capabilities(FLOW_STATS, GROUP_STATS, IP_REASM,
535 PORT_BLOCKED, PORT_STATS, QUEUE_STATS, TABLE_STATS);
539 public class ExperimenterMessageService implements IMDMessageTranslator<OfHeader, List<DataObject>> {
541 public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sw, OfHeader msg) {
542 LOG.debug("Received a packet in Experimenter Service");
543 ConnectionConductorImplTest.this.incrExperimenterMessageCounter();
548 public class PacketInMessageService implements IMDMessageTranslator<OfHeader, List<DataObject>> {
550 public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sw, OfHeader msg) {
551 LOG.debug("Received a packet in PacketIn Service");
552 ConnectionConductorImplTest.this.incrPacketinMessageCounter();
557 public class FlowRemovedMessageService implements IMDMessageTranslator<OfHeader, List<DataObject>> {
559 public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sw, OfHeader msg) {
560 LOG.debug("Received a packet in FlowRemoved Service");
561 ConnectionConductorImplTest.this.incrFlowremovedMessageCounter();
566 public class PortStatusMessageService implements IMDMessageTranslator<OfHeader, List<DataObject>> {
568 public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sw, OfHeader msg) {
569 LOG.debug("Received a packet in PortStatus Service");
570 if ((((PortStatusMessage) msg).getReason().equals(PortReason.OFPPRADD))) {
571 ConnectionConductorImplTest.this.incrPortstatusAddMessageCounter();
572 } else if (((PortStatusMessage) msg).getReason().equals(PortReason.OFPPRDELETE)) {
573 ConnectionConductorImplTest.this.incrPortstatusDeleteMessageCounter();
574 } else if (((PortStatusMessage) msg).getReason().equals(PortReason.OFPPRMODIFY)) {
575 ConnectionConductorImplTest.this.incrPortstatusModifyMessageCounter();
581 public class ErrorMessageService implements IMDMessageTranslator<OfHeader, List<DataObject>> {
583 public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sw, OfHeader msg) {
584 LOG.debug("Received a packet in Experimenter Service");
585 ConnectionConductorImplTest.this.incrErrorMessageCounter();
592 * {@link org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductorImpl#onExperimenterMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage)}
595 * @throws InterruptedException
598 public void testOnErrorMessage() throws InterruptedException {
599 simulateV13PostHandshakeState(connectionConductor);
601 ErrorMessageBuilder builder1 = new ErrorMessageBuilder();
602 builder1.setVersion((short) 4);
603 builder1.setCode(100);
604 connectionConductor.onErrorMessage(builder1.build());
605 synchronized (popListener) {
606 popListener.wait(maxProcessingTimeout);
608 Assert.assertEquals(1, errorMessageCounter);
609 builder1.setCode(200);
610 connectionConductor.onErrorMessage(builder1.build());
611 synchronized (popListener) {
612 popListener.wait(maxProcessingTimeout);
614 Assert.assertEquals(2, errorMessageCounter);
618 * @return listener mapping for:
620 * <li>experimenter</li>
624 private Map<TranslatorKey, Collection<IMDMessageTranslator<OfHeader, List<DataObject>>>> assembleTranslatorMapping() {
625 Map<TranslatorKey, Collection<IMDMessageTranslator<OfHeader, List<DataObject>>>> translatorMapping = new HashMap<>();
628 IMDMessageTranslator<OfHeader, List<DataObject>> objEms = new ExperimenterMessageService();
629 Collection<IMDMessageTranslator<OfHeader, List<DataObject>>> existingValues = new ArrayList<>();
630 existingValues.add(objEms);
631 tKey = new TranslatorKey(4, ExperimenterMessage.class.getName());
632 translatorMapping.put(tKey, existingValues);
633 IMDMessageTranslator<OfHeader, List<DataObject>> objErms = new ErrorMessageService();
634 existingValues.add(objErms);
635 tKey = new TranslatorKey(4, ErrorMessage.class.getName());
636 translatorMapping.put(tKey, existingValues);
637 return translatorMapping;
642 * {@link org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductorImpl#processPortStatusMsg(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)}
644 * Tests for getting features from port status message by port version
646 * <li>features are malformed - one of them is null</li>
647 * <li>mismatch between port version and port features</li>
648 * <li>mismatch between port version and port features</li>
649 * <li>non-existing port version</li>
650 * <li>port version OF 1.0</li>
651 * <li>port version OF 1.3</li>
655 public void testProcessPortStatusMsg() {
656 simulateV13PostHandshakeState(connectionConductor);
658 long portNumber = 90L;
659 long portNumberV10 = 91L;
660 PortStatusMessage msg;
662 PortStatusMessageBuilder builder = new PortStatusMessageBuilder();
663 PortFeatures features = new PortFeatures(true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false);
664 PortFeatures featuresMal = new PortFeatures(true, false, false, false, null, false, false, false, false, false, false, false, false, false, false, false);
665 PortFeaturesV10 featuresV10 = new PortFeaturesV10(true, false, false, false, false, false, false, false, false, false, false, false);
668 builder.setVersion((short) 1).setPortNo(portNumber).setReason(PortReason.OFPPRADD).setCurrentFeatures(featuresMal);
669 connectionConductor.processPortStatusMsg(builder.build());
670 Assert.assertTrue(connectionConductor.getSessionContext().getPortsBandwidth().isEmpty());
671 Assert.assertTrue(connectionConductor.getSessionContext().getPhysicalPorts().isEmpty());
673 //Version-features mismatch
674 builder.setCurrentFeatures(features);
675 connectionConductor.processPortStatusMsg(builder.build());
676 Assert.assertTrue(connectionConductor.getSessionContext().getPortsBandwidth().isEmpty());
677 Assert.assertTrue(connectionConductor.getSessionContext().getPhysicalPorts().isEmpty());
679 //Non existing version
680 builder.setVersion((short) 0);
681 connectionConductor.processPortStatusMsg(builder.build());
682 Assert.assertTrue(connectionConductor.getSessionContext().getPortsBandwidth().isEmpty());
683 Assert.assertTrue(connectionConductor.getSessionContext().getPhysicalPorts().isEmpty());
686 builder.setVersion((short) 4);
687 msg = builder.build();
688 connectionConductor.processPortStatusMsg(builder.build());
689 Assert.assertTrue(connectionConductor.getSessionContext().getPortBandwidth(portNumber));
690 Assert.assertEquals(connectionConductor.getSessionContext().getPhysicalPort(portNumber), msg);
693 builder.setVersion((short) 1).setPortNo(portNumberV10).setCurrentFeatures(null).setCurrentFeaturesV10(featuresV10);
694 msg = builder.build();
695 connectionConductor.processPortStatusMsg(builder.build());
696 Assert.assertTrue(connectionConductor.getSessionContext().getPortBandwidth(portNumberV10));
697 Assert.assertEquals(connectionConductor.getSessionContext().getPhysicalPort(portNumberV10), msg);
700 private void simulateV13PostHandshakeState(ConnectionConductorImpl conductor) {
701 GetFeaturesOutputBuilder featureOutput = getFeatureResponseMsg();
702 conductor.postHandshakeBasic(featureOutput.build(), OFConstants.OFP_VERSION_1_3);