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.nx.match.arp.sha.grouping.ArpShaValuesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpShaCaseValue;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpShaCaseValueBuilder;
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.NxAugMatchRpcGetFlowStats;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcAddFlowBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxArpShaKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.arp.sha.grouping.NxmNxArpShaBuilder;
35 import org.opendaylight.yangtools.yang.binding.Augmentation;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * Test for {@link ArpShaConvertor}.
42 @RunWith(MockitoJUnitRunner.class)
43 public class ArpShaConvertorTest {
46 private Extension extension;
48 private MatchEntry matchEntry;
50 private ArpShaConvertor arpShaConvertor;
52 private static final MacAddress MAC_ADDRESS = MacAddress.getDefaultInstance("01:23:45:67:89:AB");
54 private static final Logger LOG = LoggerFactory.getLogger(ArpShaConvertorTest.class);
57 public void setUp() throws Exception {
58 final NxmNxArpShaBuilder nxmNxArpShaBuilder = new NxmNxArpShaBuilder()
59 .setMacAddress(MAC_ADDRESS);
60 final NxAugMatchRpcAddFlowBuilder nxAugMatchRpcAddFlowBuilder = new NxAugMatchRpcAddFlowBuilder()
61 .setNxmNxArpSha(nxmNxArpShaBuilder.build());
62 final Augmentation<Extension> extensionAugmentation = nxAugMatchRpcAddFlowBuilder.build();
64 when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
66 arpShaConvertor = new ArpShaConvertor();
70 public void testConvertToOFJava() throws Exception {
71 final MatchEntry matchEntry = arpShaConvertor.convert(extension);
72 Assert.assertEquals(MAC_ADDRESS.getValue(), ((ArpShaCaseValue)matchEntry.getMatchEntryValue()).getArpShaValues().getMacAddress().getValue());
76 public void testConvertFromOFJava() throws Exception {
77 final ArpShaValuesBuilder arpShaValuesBuilder = new ArpShaValuesBuilder()
78 .setMacAddress(MAC_ADDRESS);
79 final ArpShaCaseValueBuilder arpShaCaseValueBuilder = new ArpShaCaseValueBuilder()
80 .setArpShaValues(arpShaValuesBuilder.build());
81 final ArpShaCaseValue arpShaCaseValue = arpShaCaseValueBuilder.build();
83 when(matchEntry.getMatchEntryValue()).thenReturn(arpShaCaseValue);
85 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = arpShaConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
86 Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(), ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxArpSha().getMacAddress());
87 Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);
89 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = arpShaConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
90 Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(), ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxArpSha().getMacAddress());
91 Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);
93 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = arpShaConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
94 Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(), ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxArpSha().getMacAddress());
95 Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);
97 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = arpShaConvertor.convert(matchEntry, MatchPath.RPCFLOWSSTATISTICS_FLOWANDSTATISTICSMAPLIST_MATCH);
98 Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(), ((NxAugMatchRpcGetFlowStats)extensionAugment3.getAugmentationObject()).getNxmNxArpSha().getMacAddress());
99 Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);