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
8 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
10 import static org.mockito.Mockito.when;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.ArgumentMatchers;
17 import org.mockito.Mock;
18 import org.mockito.junit.MockitoJUnitRunner;
19 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
20 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.ArpThaCaseValue;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.ArpThaCaseValueBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.arp.tha.grouping.ArpThaValuesBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
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.NxAugMatchRpcAddFlowBuilder;
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.NxmNxArpThaKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.arp.tha.grouping.NxmNxArpThaBuilder;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
37 * Test for {@link ArpThaConvertor}.
39 @RunWith(MockitoJUnitRunner.class)
40 public class ArpThaConvertorTest {
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 ArpThaConvertor arpThaConvertor;
54 final NxmNxArpThaBuilder nxArpThaBuilder = new NxmNxArpThaBuilder()
55 .setMacAddress(MAC_ADDRESS);
56 final NxAugMatchRpcAddFlowBuilder nxAugMatchRpcAddFlowBuilder = new NxAugMatchRpcAddFlowBuilder()
57 .setNxmNxArpTha(nxArpThaBuilder.build());
58 final Augmentation<Extension> extensionAugmentation = nxAugMatchRpcAddFlowBuilder.build();
60 when(extension.augmentation(ArgumentMatchers.any()))
61 .thenReturn(extensionAugmentation);
63 arpThaConvertor = new ArpThaConvertor();
67 public void testConvertToOFJava() {
68 final MatchEntry converted = arpThaConvertor.convert(extension);
69 Assert.assertEquals(MAC_ADDRESS.getValue(),
70 ((ArpThaCaseValue) converted.getMatchEntryValue()).getArpThaValues().getMacAddress().getValue());
74 public void testConvertFromOFJava() {
75 final ArpThaValuesBuilder arpThaValuesBuilder = new ArpThaValuesBuilder()
76 .setMacAddress(MAC_ADDRESS);
77 final ArpThaCaseValueBuilder arpThaCaseValueBuilder = new ArpThaCaseValueBuilder()
78 .setArpThaValues(arpThaValuesBuilder.build());
79 final ArpThaCaseValue arpThaCaseValue = arpThaCaseValueBuilder.build();
81 when(matchEntry.getMatchEntryValue()).thenReturn(arpThaCaseValue);
83 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = arpThaConvertor.convert(matchEntry,
84 MatchPath.PACKET_RECEIVED_MATCH);
85 Assert.assertEquals(arpThaCaseValue.getArpThaValues().getMacAddress(),
86 ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxArpTha().getMacAddress());
87 Assert.assertEquals(NxmNxArpThaKey.VALUE, extensionAugment.getKey());
89 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = arpThaConvertor
90 .convert(matchEntry, MatchPath.SWITCH_FLOW_REMOVED_MATCH);
91 Assert.assertEquals(arpThaCaseValue.getArpThaValues().getMacAddress(),
92 ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject()).getNxmNxArpTha()
94 Assert.assertEquals(NxmNxArpThaKey.VALUE, extensionAugment.getKey());
96 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = arpThaConvertor
97 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
98 Assert.assertEquals(arpThaCaseValue.getArpThaValues().getMacAddress(),
99 ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject()).getNxmNxArpTha()
101 Assert.assertEquals(NxmNxArpThaKey.VALUE, extensionAugment.getKey());
103 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = arpThaConvertor
104 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_RPC_MATCH);
105 Assert.assertEquals(arpThaCaseValue.getArpThaValues().getMacAddress(),
106 ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmNxArpTha()
108 Assert.assertEquals(NxmNxArpThaKey.VALUE, extensionAugment.getKey());