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.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.src.grouping.EthSrcValuesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.EthSrcCaseValue;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.EthSrcCaseValueBuilder;
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.NxAugMatchNotifPacketIn;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfEthSrcKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.eth.src.grouping.NxmOfEthSrcBuilder;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
37 * Test for {@link EthSrcConvertor}.
39 @RunWith(MockitoJUnitRunner.class)
40 public class EthSrcConvertorTest {
43 private Extension extension;
45 private MatchEntry matchEntry;
47 private static final MacAddress MAC_ADDRESS = MacAddress.getDefaultInstance("01:23:45:67:89:AB");
49 private EthSrcConvertor ethSrcConvertor;
52 public void setUp() throws Exception {
53 final NxmOfEthSrcBuilder nxmOfEthSrcBuilder = new NxmOfEthSrcBuilder()
54 .setMacAddress(MAC_ADDRESS);
55 final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
56 nxAugMatchNotifUpdateFlowStatsBuilder.setNxmOfEthSrc(nxmOfEthSrcBuilder.build());
58 final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
59 when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
61 ethSrcConvertor = new EthSrcConvertor();
65 public void testConvert() throws Exception {
66 final MatchEntry matchEntry = ethSrcConvertor.convert(extension);
67 Assert.assertEquals(MAC_ADDRESS, ((EthSrcCaseValue)matchEntry.getMatchEntryValue()).getEthSrcValues().getMacAddress());
71 public void testConvert1() throws Exception {
72 final EthSrcValuesBuilder ethSrcValuesBuilder = new EthSrcValuesBuilder()
73 .setMacAddress(MAC_ADDRESS);
74 final EthSrcCaseValueBuilder ethSrcCaseValueBuilder = new EthSrcCaseValueBuilder()
75 .setEthSrcValues(ethSrcValuesBuilder.build());
77 final EthSrcCaseValue ethSrcCaseValue = ethSrcCaseValueBuilder.build();
79 when(matchEntry.getMatchEntryValue()).thenReturn(ethSrcCaseValue);
81 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = ethSrcConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
82 Assert.assertEquals(MAC_ADDRESS, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfEthSrc().getMacAddress());
83 Assert.assertEquals(extensionAugment.getKey(), NxmOfEthSrcKey.class);
85 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = ethSrcConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
86 Assert.assertEquals(MAC_ADDRESS, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfEthSrc().getMacAddress());
87 Assert.assertEquals(extensionAugment.getKey(), NxmOfEthSrcKey.class);
89 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = ethSrcConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
90 Assert.assertEquals(MAC_ADDRESS, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfEthSrc().getMacAddress());
91 Assert.assertEquals(extensionAugment.getKey(), NxmOfEthSrcKey.class);