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 / NshFlagsConvertorTest.java
1 /*
2  * Copyright (c) 2018 SUSE LINUX GmbH.  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.junit.Assert.assertEquals;
12 import static org.mockito.Mockito.when;
13
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.NshFlagsCaseValue;
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.NxmNxNshFlagsKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nsh.flags.grouping.NxmNxNshFlags;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nsh.flags.grouping.NxmNxNshFlagsBuilder;
36 import org.opendaylight.yangtools.yang.binding.Augmentation;
37
38 @RunWith(MockitoJUnitRunner.class)
39 public class NshFlagsConvertorTest {
40     @Mock
41     private Extension extension;
42
43     private NshFlagsConvertor convertor;
44     private static final Short FLAGS_VALUE = (short) 0x7B;
45     private static final Short MASK_VALUE = (short) 0xFF;
46
47     @Before
48     public void setUp() throws Exception {
49         NxmNxNshFlags nxmNxNshFlags = new NxmNxNshFlagsBuilder()
50                 .setNshFlags(FLAGS_VALUE)
51                 .setMask(MASK_VALUE)
52                 .build();
53         NxAugMatchNodesNodeTableFlow nxAugMatchNotifUpdateFlowStats = new NxAugMatchNodesNodeTableFlowBuilder()
54                 .setNxmNxNshFlags(nxmNxNshFlags)
55                 .build();
56         when(extension.augmentation(ArgumentMatchers.<Class<Augmentation<Extension>>>any()))
57                 .thenReturn(nxAugMatchNotifUpdateFlowStats);
58
59         convertor = new NshFlagsConvertor();
60     }
61
62     @Test
63     public void testConvertToOFJava() {
64
65         final MatchEntry converted = convertor.convert(extension);
66
67         ExperimenterIdCase experimenterIdCase = (ExperimenterIdCase) converted.getMatchEntryValue();
68         OfjAugNxExpMatch ofjAugNxExpMatch = experimenterIdCase.augmentation(OfjAugNxExpMatch.class);
69         NshFlagsCaseValue nshFlagsCaseValue = (NshFlagsCaseValue) ofjAugNxExpMatch.getNxExpMatchEntryValue();
70         assertEquals(NiciraConstants.NX_NSH_VENDOR_ID,
71                 experimenterIdCase.getExperimenter().getExperimenter().getValue());
72         assertEquals(FLAGS_VALUE, nshFlagsCaseValue.getNshFlagsValues().getNshFlags());
73         assertEquals(MASK_VALUE, nshFlagsCaseValue.getNshFlagsValues().getMask());
74     }
75
76     @Test
77     public void testConvertToOFSal() {
78         MatchEntry matchEntry = NshFlagsConvertor.buildMatchEntry(FLAGS_VALUE, MASK_VALUE);
79
80         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = convertor.convert(matchEntry,
81                 MatchPath.PACKET_RECEIVED_MATCH);
82         assertEquals(FLAGS_VALUE, ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject())
83                 .getNxmNxNshFlags().getNshFlags());
84         assertEquals(MASK_VALUE, ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject())
85                 .getNxmNxNshFlags().getMask());
86         assertEquals(extensionAugment.getKey(), NxmNxNshFlagsKey.class);
87
88         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = convertor.convert(matchEntry,
89                 MatchPath.SWITCH_FLOW_REMOVED_MATCH);
90         assertEquals(FLAGS_VALUE, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
91                 .getNxmNxNshFlags().getNshFlags());
92         assertEquals(MASK_VALUE, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
93                 .getNxmNxNshFlags().getMask());
94         assertEquals(extensionAugment.getKey(), NxmNxNshFlagsKey.class);
95
96         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = convertor.convert(matchEntry,
97                 MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
98         assertEquals(FLAGS_VALUE, ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
99                 .getNxmNxNshFlags().getNshFlags());
100         assertEquals(MASK_VALUE, ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
101                 .getNxmNxNshFlags().getMask());
102         assertEquals(extensionAugment.getKey(), NxmNxNshFlagsKey.class);
103
104         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = convertor.convert(matchEntry,
105                 MatchPath.FLOWS_STATISTICS_RPC_MATCH);
106         assertEquals(FLAGS_VALUE, ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject())
107                 .getNxmNxNshFlags().getNshFlags());
108         assertEquals(MASK_VALUE, ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject())
109                 .getNxmNxNshFlags().getMask());
110         assertEquals(extensionAugment.getKey(), NxmNxNshFlagsKey.class);
111     }
112 }