2 * Copyright (c) 2016 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.extension.vendor.nicira.convertor.match;
10 import static org.mockito.Mockito.when;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.ArgumentMatchers;
17 import org.mockito.Mock;
18 import org.mockito.junit.MockitoJUnitRunner;
19 import org.opendaylight.openflowjava.nx.api.NiciraConstants;
20 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
21 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.experimenter.id.match.entry.ExperimenterIdCase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.OfjAugNxExpMatch;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.exp.match.nx.exp.match.entry.value.NshcCaseValue;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNshc4Key;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nshc._4.grouping.NxmNxNshc4;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nshc._4.grouping.NxmNxNshc4Builder;
35 import org.opendaylight.yangtools.yang.binding.Augmentation;
36 import org.opendaylight.yangtools.yang.common.Uint32;
39 * Test for {@link Nshc4Convertor}.
41 @RunWith(MockitoJUnitRunner.class)
42 public class Nshc4ConvertorTest {
44 private Extension extension;
46 private Nshc4Convertor nshc4Convertor;
48 private static final Uint32 NSHC4_VALUE = Uint32.valueOf(0xFFFFFFFFL);
49 private static final Uint32 MASK_VALUE = Uint32.valueOf(0xFFFFFFFFL);
53 NxmNxNshc4 nxmNxNshc4 = new NxmNxNshc4Builder().setValue(NSHC4_VALUE).setMask(MASK_VALUE).build();
54 NxAugMatchNodesNodeTableFlow nxAugMatchNotifUpdateFlowStats = new NxAugMatchNodesNodeTableFlowBuilder()
55 .setNxmNxNshc4(nxmNxNshc4)
57 when(extension.augmentation(ArgumentMatchers.any()))
58 .thenReturn(nxAugMatchNotifUpdateFlowStats);
60 nshc4Convertor = new Nshc4Convertor();
64 public void testConvertToOFJava() {
65 final MatchEntry converted = nshc4Convertor.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(NSHC4_VALUE, nshcCaseValue.getNshc());
72 Assert.assertEquals(MASK_VALUE, nshcCaseValue.getMask());
76 public void testConvertToOFSal() {
77 MatchEntry matchEntry = Nshc4Convertor.buildMatchEntry(NSHC4_VALUE, MASK_VALUE);
79 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = nshc4Convertor.convert(matchEntry,
80 MatchPath.PACKET_RECEIVED_MATCH);
81 Assert.assertEquals(NSHC4_VALUE,
82 ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxNshc4().getValue());
83 Assert.assertEquals(MASK_VALUE,
84 ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxNshc4().getMask());
85 Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc4Key.class);
87 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = nshc4Convertor.convert(matchEntry,
88 MatchPath.SWITCH_FLOW_REMOVED_MATCH);
89 Assert.assertEquals(NSHC4_VALUE,
90 ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
91 .getNxmNxNshc4().getValue());
92 Assert.assertEquals(MASK_VALUE,
93 ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
94 .getNxmNxNshc4().getMask());
95 Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc4Key.class);
97 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = nshc4Convertor.convert(matchEntry,
98 MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
99 Assert.assertEquals(NSHC4_VALUE,
100 ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject()).getNxmNxNshc4().getValue());
101 Assert.assertEquals(MASK_VALUE,
102 ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject()).getNxmNxNshc4().getMask());
103 Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc4Key.class);
105 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = nshc4Convertor.convert(matchEntry,
106 MatchPath.FLOWS_STATISTICS_RPC_MATCH);
107 Assert.assertEquals(NSHC4_VALUE,
108 ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmNxNshc4().getValue());
109 Assert.assertEquals(MASK_VALUE,
110 ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmNxNshc4().getMask());
111 Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc4Key.class);