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.NxAugMatchNodesNodeTableFlow;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
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.NxAugMatchRpcGetFlowStats;
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()))
65 .thenReturn(extensionAugmentation);
67 arpShaConvertor = new ArpShaConvertor();
71 public void testConvertToOFJava() throws Exception {
72 final MatchEntry converted = arpShaConvertor.convert(extension);
73 Assert.assertEquals(MAC_ADDRESS.getValue(),
74 ((ArpShaCaseValue) converted.getMatchEntryValue()).getArpShaValues().getMacAddress().getValue());
78 public void testConvertFromOFJava() throws Exception {
79 final ArpShaValuesBuilder arpShaValuesBuilder = new ArpShaValuesBuilder()
80 .setMacAddress(MAC_ADDRESS);
81 final ArpShaCaseValueBuilder arpShaCaseValueBuilder = new ArpShaCaseValueBuilder()
82 .setArpShaValues(arpShaValuesBuilder.build());
83 final ArpShaCaseValue arpShaCaseValue = arpShaCaseValueBuilder.build();
85 when(matchEntry.getMatchEntryValue()).thenReturn(arpShaCaseValue);
87 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = arpShaConvertor.convert(matchEntry,
88 MatchPath.PACKET_RECEIVED_MATCH);
89 Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(),
90 ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxArpSha().getMacAddress());
91 Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);
93 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = arpShaConvertor
94 .convert(matchEntry, MatchPath.SWITCH_FLOW_REMOVED_MATCH);
95 Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(),
96 ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject()).getNxmNxArpSha()
98 Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);
100 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = arpShaConvertor
101 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
102 Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(),
103 ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject()).getNxmNxArpSha()
105 Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);
107 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = arpShaConvertor
108 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_RPC_MATCH);
109 Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(),
110 ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmNxArpSha()
112 Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);