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
8 package org.opendaylight.openflowplugin.openflow.md.core;
10 import java.util.List;
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;
19 import com.google.common.collect.Lists;
25 public class HandshakeManagerImplTest {
27 private HandshakeManagerImpl handshakeManager;
28 protected ConnectionAdapterStackImpl adapter;
31 * invoked before every test method
35 adapter = new ConnectionAdapterStackImpl();
36 handshakeManager = new HandshakeManagerImpl(adapter, (short) 4, ConnectionConductor.versionOrder);
40 * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.HandshakeManagerImpl#proposeCommonBitmapVersion(java.util.List)}.
43 public void testProposeCommonBitmapVersion() {
44 Boolean[][] versions = new Boolean[][] {
45 {true, true, true, false, false, false},
46 {true, true, true, false, false}
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);
60 * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.HandshakeManagerImpl#proposeNextVersion(short)}.
63 public void testProposeNextVersion() {
64 short[] remoteVer = new short[] { 0x05, 0x04, 0x03, 0x02, 0x01, 0x8f,
66 short[] expectedProposal = new short[] { 0x04, 0x04, 0x01, 0x01, 0x01,
69 for (int i = 0; i < remoteVer.length; i++) {
70 short actualProposal = handshakeManager
71 .proposeNextVersion(remoteVer[i]);
73 String.format("proposing for version: %04x", remoteVer[i]),
74 expectedProposal[i], actualProposal);
78 handshakeManager.proposeNextVersion((short) 0);
79 Assert.fail("there should be no proposition for this version");
80 } catch (Exception e) {