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
9 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
11 import static org.mockito.Mockito.when;
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.Matchers;
18 import org.mockito.Mock;
19 import org.mockito.runners.MockitoJUnitRunner;
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.oxm.rev150225.match.entries.grouping.MatchEntry;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nshc._4.grouping.Nshc4ValuesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc4CaseValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc4CaseValueBuilder;
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.NxmNxNshc4Builder;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
37 * Test for {@link Nshc4Convertor}.
39 @RunWith(MockitoJUnitRunner.class)
40 public class Nshc4ConvertorTest {
42 private Extension extension;
44 private MatchEntry matchEntry;
46 private Nshc4Convertor nshc4Convertor;
49 public void setUp() throws Exception {
50 final NxmNxNshc4Builder nxmNxNshc4Builder = new NxmNxNshc4Builder()
52 final NxAugMatchNodesNodeTableFlowBuilder nxAugMatchNotifUpdateFlowStatsBuilder =
53 new NxAugMatchNodesNodeTableFlowBuilder();
54 nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxNshc4(nxmNxNshc4Builder.build());
56 final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
57 when(extension.augmentation(Matchers.<Class<Augmentation<Extension>>>any()))
58 .thenReturn(extensionAugmentation);
60 nshc4Convertor = new Nshc4Convertor();
64 public void testConvert() throws Exception {
65 final MatchEntry converted = nshc4Convertor.convert(extension);
66 Assert.assertEquals(1, ((Nshc4CaseValue)converted.getMatchEntryValue()).getNshc4Values().getNshc().intValue());
70 public void testConvert1() throws Exception {
71 final Nshc4ValuesBuilder nshc4ValuesBuilder = new Nshc4ValuesBuilder()
72 .setNshc(Long.valueOf(1));
73 final Nshc4CaseValueBuilder nshc4CaseValueBuilder = new Nshc4CaseValueBuilder()
74 .setNshc4Values(nshc4ValuesBuilder.build());
76 final Nshc4CaseValue nshc4CaseValue = nshc4CaseValueBuilder.build();
78 when(matchEntry.getMatchEntryValue()).thenReturn(nshc4CaseValue);
80 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = nshc4Convertor.convert(matchEntry,
81 MatchPath.PACKET_RECEIVED_MATCH);
82 Assert.assertEquals(1, ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxNshc4()
83 .getValue().intValue());
84 Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc4Key.class);
86 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = nshc4Convertor.convert(matchEntry,
87 MatchPath.SWITCH_FLOW_REMOVED_MATCH);
88 Assert.assertEquals(1, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
89 .getNxmNxNshc4().getValue().intValue());
90 Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc4Key.class);
92 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = nshc4Convertor.convert(matchEntry,
93 MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
94 Assert.assertEquals(1, ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
95 .getNxmNxNshc4().getValue().intValue());
96 Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc4Key.class);
98 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = nshc4Convertor.convert(matchEntry,
99 MatchPath.FLOWS_STATISTICS_RPC_MATCH);
100 Assert.assertEquals(1, ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmNxNshc4()
101 .getValue().intValue());
102 Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc4Key.class);