preparing QueueKeeper and message translation
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / HandshakeManagerImplTest.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowplugin.openflow.md.core;
9
10 import java.util.List;
11
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.openflowplugin.openflow.md.core.plan.ConnectionAdapterStackImpl;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder;
18
19 import com.google.common.collect.Lists;
20
21 /**
22  * @author mirehak
23  *
24  */
25 public class HandshakeManagerImplTest {
26     
27     private HandshakeManagerImpl handshakeManager;
28     protected ConnectionAdapterStackImpl adapter;
29     
30     /**
31      * invoked before every test method
32      */
33     @Before
34     public void setUp() {
35         adapter = new ConnectionAdapterStackImpl();
36         handshakeManager = new HandshakeManagerImpl(adapter, (short) 4, ConnectionConductor.versionOrder);
37     }
38
39     /**
40      * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.HandshakeManagerImpl#proposeCommonBitmapVersion(java.util.List)}.
41      */
42     @Test
43     public void testProposeCommonBitmapVersion() {
44         Boolean[][] versions = new Boolean[][] {
45                 {true, true, true, false, false, false},
46                 {true, true, true, false, false}
47         };
48         
49         for (Boolean[] verasionList : versions) {
50             ElementsBuilder elementsBuilder = new ElementsBuilder();
51             elementsBuilder.setVersionBitmap(Lists.newArrayList(verasionList));
52             Elements element = elementsBuilder.build();
53             List<Elements> elements = Lists.newArrayList(element );
54             Short proposal = handshakeManager.proposeCommonBitmapVersion(elements);
55             Assert.assertEquals(Short.valueOf((short)1), proposal);
56         }
57     }
58
59     /**
60      * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.HandshakeManagerImpl#proposeNextVersion(short)}.
61      */
62     @Test
63     public void testProposeNextVersion() {
64         short[] remoteVer = new short[] { 0x05, 0x04, 0x03, 0x02, 0x01, 0x8f,
65                 0xff };
66         short[] expectedProposal = new short[] { 0x04, 0x04, 0x01, 0x01, 0x01,
67                 0x04, 0x04 };
68
69         for (int i = 0; i < remoteVer.length; i++) {
70             short actualProposal = handshakeManager
71                     .proposeNextVersion(remoteVer[i]);
72             Assert.assertEquals(
73                     String.format("proposing for version: %04x", remoteVer[i]),
74                     expectedProposal[i], actualProposal);
75         }
76
77         try {
78             handshakeManager.proposeNextVersion((short) 0);
79             Assert.fail("there should be no proposition for this version");
80         } catch (Exception e) {
81             // expected
82         }
83     }
84
85 }