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.NxAugMatchRpcAddFlowBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxArpShaKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.arp.sha.grouping.NxmNxArpShaBuilder;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 * Test for {@link ArpShaConvertor}.
41 @RunWith(MockitoJUnitRunner.class)
42 public class ArpShaConvertorTest {
45 private Extension extension;
47 private MatchEntry matchEntry;
49 private ArpShaConvertor arpShaConvertor;
51 private static final MacAddress MAC_ADDRESS = MacAddress.getDefaultInstance("01:23:45:67:89:AB");
53 private static final Logger LOG = LoggerFactory.getLogger(ArpShaConvertorTest.class);
56 public void setUp() throws Exception {
57 final NxmNxArpShaBuilder nxmNxArpShaBuilder = new NxmNxArpShaBuilder()
58 .setMacAddress(MAC_ADDRESS);
59 final NxAugMatchRpcAddFlowBuilder nxAugMatchRpcAddFlowBuilder = new NxAugMatchRpcAddFlowBuilder()
60 .setNxmNxArpSha(nxmNxArpShaBuilder.build());
61 final Augmentation<Extension> extensionAugmentation = nxAugMatchRpcAddFlowBuilder.build();
63 when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
65 arpShaConvertor = new ArpShaConvertor();
69 public void testConvertToOFJava() throws Exception {
70 final MatchEntry matchEntry = arpShaConvertor.convert(extension);
71 Assert.assertEquals(MAC_ADDRESS.getValue(), ((ArpShaCaseValue)matchEntry.getMatchEntryValue()).getArpShaValues().getMacAddress().getValue());
75 public void testConvertFromOFJava() throws Exception {
76 final ArpShaValuesBuilder arpShaValuesBuilder = new ArpShaValuesBuilder()
77 .setMacAddress(MAC_ADDRESS);
78 final ArpShaCaseValueBuilder arpShaCaseValueBuilder = new ArpShaCaseValueBuilder()
79 .setArpShaValues(arpShaValuesBuilder.build());
80 final ArpShaCaseValue arpShaCaseValue = arpShaCaseValueBuilder.build();
82 when(matchEntry.getMatchEntryValue()).thenReturn(arpShaCaseValue);
84 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = arpShaConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
85 Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(), ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxArpSha().getMacAddress());
86 Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);
88 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = arpShaConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
89 Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(), ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxArpSha().getMacAddress());
90 Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);
92 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = arpShaConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
93 Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(), ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxArpSha().getMacAddress());
94 Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);