OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / test / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / match / Nshc2ConvertorTest.java
1 /**
2  * Copyright (c) 2016 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
9 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
10
11 import static org.mockito.Mockito.when;
12
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.ArgumentMatchers;
18 import org.mockito.Mock;
19 import org.mockito.runners.MockitoJUnitRunner;
20 import org.opendaylight.openflowjava.nx.api.NiciraConstants;
21 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
22 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.OfjAugNxExpMatch;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.experimenter.id._case.nx.exp.match.entry.value.NshcCaseValue;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNshc2Key;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nshc._2.grouping.NxmNxNshc2;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nshc._2.grouping.NxmNxNshc2Builder;
36 import org.opendaylight.yangtools.yang.binding.Augmentation;
37
38 /**
39  * Test for {@link Nshc2Convertor}.
40  */
41 @RunWith(MockitoJUnitRunner.class)
42 public class Nshc2ConvertorTest {
43     @Mock
44     private Extension extension;
45
46     private Nshc2Convertor nshc2Convertor;
47
48     private static final Long NSHC2_VALUE = 0xFFFFFFFFL;
49     private static final Long MASK_VALUE = 0xFFFFFFFFL;
50
51     @Before
52     public void setUp() throws Exception {
53         NxmNxNshc2 nxmNxNshc2 = new NxmNxNshc2Builder().setValue(NSHC2_VALUE).setMask(MASK_VALUE).build();
54         NxAugMatchNodesNodeTableFlow nxAugMatchNotifUpdateFlowStats = new NxAugMatchNodesNodeTableFlowBuilder()
55                 .setNxmNxNshc2(nxmNxNshc2)
56                 .build();
57         when(extension.augmentation(ArgumentMatchers.<Class<Augmentation<Extension>>>any()))
58                 .thenReturn(nxAugMatchNotifUpdateFlowStats);
59
60         nshc2Convertor = new Nshc2Convertor();
61     }
62
63     @Test
64     public void testConvertToOFJava() {
65         final MatchEntry converted = nshc2Convertor.convert(extension);
66         ExperimenterIdCase experimenterIdCase = (ExperimenterIdCase) converted.getMatchEntryValue();
67         OfjAugNxExpMatch ofjAugNxExpMatch = experimenterIdCase.augmentation(OfjAugNxExpMatch.class);
68         NshcCaseValue nshcCaseValue = (NshcCaseValue) ofjAugNxExpMatch.getNxExpMatchEntryValue();
69         Assert.assertEquals(NiciraConstants.NX_NSH_VENDOR_ID,
70                 experimenterIdCase.getExperimenter().getExperimenter().getValue());
71         Assert.assertEquals(NSHC2_VALUE, nshcCaseValue.getNshc());
72         Assert.assertEquals(MASK_VALUE, nshcCaseValue.getMask());
73     }
74
75     @Test
76     public void testConvertToOFSal() {
77         MatchEntry matchEntry = Nshc2Convertor.buildMatchEntry(NSHC2_VALUE, MASK_VALUE);
78
79         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = nshc2Convertor.convert(matchEntry,
80                 MatchPath.PACKET_RECEIVED_MATCH);
81         Assert.assertEquals(NSHC2_VALUE,
82                 ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxNshc2().getValue());
83         Assert.assertEquals(MASK_VALUE,
84                 ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxNshc2().getMask());
85         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc2Key.class);
86
87         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = nshc2Convertor.convert(matchEntry,
88                 MatchPath.SWITCH_FLOW_REMOVED_MATCH);
89         Assert.assertEquals(NSHC2_VALUE,
90                 ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
91                         .getNxmNxNshc2().getValue());
92         Assert.assertEquals(MASK_VALUE,
93                 ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
94                         .getNxmNxNshc2().getMask());
95         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc2Key.class);
96
97         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = nshc2Convertor.convert(matchEntry,
98                 MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
99         Assert.assertEquals(NSHC2_VALUE,
100                 ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject()).getNxmNxNshc2().getValue());
101         Assert.assertEquals(MASK_VALUE,
102                 ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject()).getNxmNxNshc2().getMask());
103         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc2Key.class);
104
105         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = nshc2Convertor.convert(matchEntry,
106                 MatchPath.FLOWS_STATISTICS_RPC_MATCH);
107         Assert.assertEquals(NSHC2_VALUE,
108                 ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmNxNshc2().getValue());
109         Assert.assertEquals(MASK_VALUE,
110                 ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmNxNshc2().getMask());
111         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc2Key.class);
112     }
113 }