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 java.math.BigInteger;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Matchers;
19 import org.mockito.Mock;
20 import org.mockito.runners.MockitoJUnitRunner;
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.oxm.rev150225.match.entries.grouping.MatchEntry;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.id.grouping.TunIdValuesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIdCaseValue;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIdCaseValueBuilder;
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.NxmNxTunIdKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.id.grouping.NxmNxTunIdBuilder;
35 import org.opendaylight.yangtools.yang.binding.Augmentation;
38 * Test for {@link TunIdConvertor}.
40 @RunWith(MockitoJUnitRunner.class)
41 public class TunIdConvertorTest {
43 private Extension extension;
45 private MatchEntry matchEntry;
47 private TunIdConvertor tunIdConvertor;
50 public void setUp() throws Exception {
51 final NxmNxTunIdBuilder nxmNxTunIdBuilder = new NxmNxTunIdBuilder()
52 .setValue(BigInteger.ONE);
53 final NxAugMatchNodesNodeTableFlowBuilder nxAugMatchNotifUpdateFlowStatsBuilder =
54 new NxAugMatchNodesNodeTableFlowBuilder();
55 nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxTunId(nxmNxTunIdBuilder.build());
57 final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
58 when(extension.augmentation(Matchers.<Class<Augmentation<Extension>>>any()))
59 .thenReturn(extensionAugmentation);
61 tunIdConvertor = new TunIdConvertor();
65 public void testConvert() throws Exception {
66 final MatchEntry converted = tunIdConvertor.convert(extension);
67 Assert.assertEquals(BigInteger.ONE, ((TunIdCaseValue)converted.getMatchEntryValue())
68 .getTunIdValues().getValue());
72 public void testConvert1() throws Exception {
73 final TunIdValuesBuilder tunIdValuesBuilder = new TunIdValuesBuilder()
74 .setValue(BigInteger.TEN);
75 final TunIdCaseValueBuilder tunIdCaseValueBuilder = new TunIdCaseValueBuilder()
76 .setTunIdValues(tunIdValuesBuilder.build());
78 final TunIdCaseValue tunIdCaseValue = tunIdCaseValueBuilder.build();
80 when(matchEntry.getMatchEntryValue()).thenReturn(tunIdCaseValue);
82 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = tunIdConvertor.convert(matchEntry,
83 MatchPath.PACKET_RECEIVED_MATCH);
84 Assert.assertEquals(BigInteger.TEN,
85 ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxTunId().getValue());
86 Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIdKey.class);
88 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = tunIdConvertor.convert(matchEntry,
89 MatchPath.SWITCH_FLOW_REMOVED_MATCH);
90 Assert.assertEquals(BigInteger.TEN,
91 ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject()).getNxmNxTunId()
93 Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIdKey.class);
95 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = tunIdConvertor.convert(matchEntry,
96 MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
97 Assert.assertEquals(BigInteger.TEN,
98 ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject()).getNxmNxTunId().getValue());
99 Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIdKey.class);
101 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = tunIdConvertor.convert(matchEntry,
102 MatchPath.FLOWS_STATISTICS_RPC_MATCH);
103 Assert.assertEquals(BigInteger.TEN,
104 ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmNxTunId().getValue());
105 Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIdKey.class);