fbc693beae1e1e8b894d06bc9504a62f2cda48d4
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / test / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / match / EthDstConvertorTest.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.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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
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.of.match.eth.dst.grouping.EthDstValuesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.EthDstCaseValue;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.EthDstCaseValueBuilder;
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.NxmOfEthDstKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.eth.dst.grouping.NxmOfEthDstBuilder;
35 import org.opendaylight.yangtools.yang.binding.Augmentation;
36
37 /**
38  * Test for {@link EthDstConvertor}.
39  */
40 @RunWith(MockitoJUnitRunner.class)
41 public class EthDstConvertorTest {
42
43     @Mock
44     private Extension extension;
45     @Mock
46     private MatchEntry matchEntry;
47
48     private static final MacAddress MAC_ADDRESS =  MacAddress.getDefaultInstance("01:23:45:67:89:AB");
49
50     private EthDstConvertor ethDstConvertor;
51
52     @Before
53     public void setUp() throws Exception {
54
55         final NxmOfEthDstBuilder nxmOfEthDstBuilder = new NxmOfEthDstBuilder()
56                 .setMacAddress(MAC_ADDRESS);
57         final NxAugMatchNodesNodeTableFlowBuilder nxAugMatchNotifUpdateFlowStatsBuilder =
58                 new NxAugMatchNodesNodeTableFlowBuilder();
59         nxAugMatchNotifUpdateFlowStatsBuilder.setNxmOfEthDst(nxmOfEthDstBuilder.build());
60
61         final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
62         when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any()))
63             .thenReturn(extensionAugmentation);
64
65         ethDstConvertor = new EthDstConvertor();
66
67     }
68
69     @Test
70     public void testConvert() throws Exception {
71         final MatchEntry converted = ethDstConvertor.convert(extension);
72         Assert.assertEquals(MAC_ADDRESS, ((EthDstCaseValue)converted.getMatchEntryValue())
73                 .getEthDstValues().getMacAddress());
74     }
75
76     @Test
77     public void testConvert1() throws Exception {
78         final EthDstValuesBuilder ethDstValuesBuilder = new EthDstValuesBuilder()
79                 .setMacAddress(MAC_ADDRESS);
80         final EthDstCaseValueBuilder ethDstCaseValueBuilder = new EthDstCaseValueBuilder()
81                 .setEthDstValues(ethDstValuesBuilder.build());
82
83         final EthDstCaseValue ethDstCaseValue = ethDstCaseValueBuilder.build();
84
85         when(matchEntry.getMatchEntryValue()).thenReturn(ethDstCaseValue);
86
87         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = ethDstConvertor.convert(matchEntry,
88                 MatchPath.PACKET_RECEIVED_MATCH);
89         Assert.assertEquals(MAC_ADDRESS,
90                 ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmOfEthDst().getMacAddress());
91         Assert.assertEquals(extensionAugment.getKey(), NxmOfEthDstKey.class);
92
93         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = ethDstConvertor
94                 .convert(matchEntry, MatchPath.SWITCH_FLOW_REMOVED_MATCH);
95         Assert.assertEquals(MAC_ADDRESS, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
96                 .getNxmOfEthDst().getMacAddress());
97         Assert.assertEquals(extensionAugment.getKey(), NxmOfEthDstKey.class);
98
99         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = ethDstConvertor
100                 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
101         Assert.assertEquals(MAC_ADDRESS, ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
102                 .getNxmOfEthDst().getMacAddress());
103         Assert.assertEquals(extensionAugment.getKey(), NxmOfEthDstKey.class);
104
105         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = ethDstConvertor
106                 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_RPC_MATCH);
107         Assert.assertEquals(MAC_ADDRESS, ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject())
108                 .getNxmOfEthDst().getMacAddress());
109         Assert.assertEquals(extensionAugment.getKey(), NxmOfEthDstKey.class);
110     }
111 }