Add method to register listener for unknown msg
[openflowjava.git] / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / keys / KeysTest.java
1 /*
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. 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.openflowjava.protocol.api.keys;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
13 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.action.container.action.choice.ExperimenterIdCase;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.ExperimenterActionSubType;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
18
19 /**
20  * @author michal.polkorab
21  */
22 public class KeysTest {
23
24     /**
25      * Testing equals() and hashcode() methods of extension deserializer's keys
26      */
27     @Test
28     public void testEqualsAndHashcodeOfDeserializerKeys() {
29         ActionDeserializerKey actionDeserializerKey = new ActionDeserializerKey(EncodeConstants.OF13_VERSION_ID,
30                 EncodeConstants.EXPERIMENTER_VALUE, 1L);
31         ExperimenterActionDeserializerKey experimenterActionDeserializerKey = new ExperimenterActionDeserializerKey(
32                 EncodeConstants.OF13_VERSION_ID, 1L);
33         Assert.assertEquals(actionDeserializerKey, experimenterActionDeserializerKey);
34         Assert.assertEquals(actionDeserializerKey.hashCode(), experimenterActionDeserializerKey.hashCode());
35
36         InstructionDeserializerKey instructionDeserializerKey = new InstructionDeserializerKey(
37                 EncodeConstants.OF13_VERSION_ID, EncodeConstants.EXPERIMENTER_VALUE, 1L);
38         ExperimenterInstructionDeserializerKey experimenterInstructionDeserializerKey = new ExperimenterInstructionDeserializerKey(
39                 EncodeConstants.OF13_VERSION_ID, 1L);
40         Assert.assertEquals(instructionDeserializerKey, experimenterInstructionDeserializerKey);
41         Assert.assertEquals(instructionDeserializerKey.hashCode(), experimenterInstructionDeserializerKey.hashCode());
42
43         MatchEntryDeserializerKey matchKey = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
44                 OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
45         MatchEntryDeserializerKey matchKey2 = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
46                 OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
47         Assert.assertEquals(matchKey, matchKey2);
48         Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
49     }
50
51     /**
52      * Testing equals() and hashcode() methods of extension serializer's keys
53      */
54     @Test
55     public void testEqualsAndHashcodeOfActionDeserializerKeys() {
56         ActionSerializerKey<ExperimenterIdCase> actionSerializerKey = new ActionSerializerKey<>(
57                 EncodeConstants.OF13_VERSION_ID, ExperimenterIdCase.class, 1L);
58         ExperimenterActionSerializerKey experimenterActionSerializerKey = new ExperimenterActionSerializerKey(
59                 EncodeConstants.OF13_VERSION_ID, 1L, ExpSubType.class);
60         Assert.assertFalse(actionSerializerKey.equals(experimenterActionSerializerKey));
61         Assert.assertFalse(experimenterActionSerializerKey.equals(actionSerializerKey));
62
63         InstructionSerializerKey<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225
64         .instruction.container.instruction.choice.ExperimenterIdCase> instructionSerializerKey =
65                 new InstructionSerializerKey<>(EncodeConstants.OF13_VERSION_ID, org.opendaylight.yang.gen.v1.urn
66                         .opendaylight.openflow.augments.rev150225.instruction.container.instruction.choice
67                         .ExperimenterIdCase.class, 1L);
68         ExperimenterInstructionSerializerKey experimenterInstructionSerializerKey = new ExperimenterInstructionSerializerKey(EncodeConstants.OF13_VERSION_ID, 1L);
69         Assert.assertEquals(instructionSerializerKey, experimenterInstructionSerializerKey);
70         Assert.assertEquals(instructionSerializerKey.hashCode(), experimenterInstructionSerializerKey.hashCode());
71
72         MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey = new MatchEntrySerializerKey<>(
73                 EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
74         MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey2 = new MatchEntrySerializerKey<>(
75                 EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
76         Assert.assertEquals(matchKey, matchKey2);
77         Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
78     }
79
80     private static class ExpSubType extends ExperimenterActionSubType {
81         // empty class - only used in test for comparation
82     }
83
84 }