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.runners.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.inet.types.rev130715.PortNumber;
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.nxm.of.match.udp.src.grouping.UdpSrcValuesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpSrcCaseValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.UdpSrcCaseValueBuilder;
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.NxAugMatchNodesNodeTableFlowBuilder;
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.NxAugMatchRpcGetFlowStats;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfUdpSrcKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.udp.src.grouping.NxmOfUdpSrcBuilder;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
37 * Test for {@link UdpSrcConvertor}.
39 @RunWith(MockitoJUnitRunner.class)
40 public class UdpSrcConvertorTest {
42 private Extension extension;
44 private MatchEntry matchEntry;
46 private static final PortNumber DEFAULT_PORT = new PortNumber(9999);
48 private UdpSrcConvertor udpSrcConvertor;
52 final NxmOfUdpSrcBuilder nxmOfUdpSrcBuilder = new NxmOfUdpSrcBuilder()
54 .setPort(DEFAULT_PORT);
55 final NxAugMatchNodesNodeTableFlowBuilder nxAugMatchNotifUpdateFlowStatsBuilder =
56 new NxAugMatchNodesNodeTableFlowBuilder();
57 nxAugMatchNotifUpdateFlowStatsBuilder.setNxmOfUdpSrc(nxmOfUdpSrcBuilder.build());
59 final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
60 when(extension.augmentation(ArgumentMatchers.any()))
61 .thenReturn(extensionAugmentation);
63 udpSrcConvertor = new UdpSrcConvertor();
67 public void testConvert() {
68 final MatchEntry converted = udpSrcConvertor.convert(extension);
69 Assert.assertEquals(Integer.valueOf(1),
70 ((UdpSrcCaseValue) converted.getMatchEntryValue()).getUdpSrcValues().getMask());
71 Assert.assertEquals(DEFAULT_PORT,
72 ((UdpSrcCaseValue) converted.getMatchEntryValue()).getUdpSrcValues().getPort());
76 public void testConvert1() {
77 final UdpSrcValuesBuilder udpSrcValuesBuilder = new UdpSrcValuesBuilder()
79 .setPort(DEFAULT_PORT);
80 final UdpSrcCaseValueBuilder udpSrcCaseValueBuilder = new UdpSrcCaseValueBuilder()
81 .setUdpSrcValues(udpSrcValuesBuilder.build());
83 final UdpSrcCaseValue udpSrcCaseValue = udpSrcCaseValueBuilder.build();
85 when(matchEntry.getMatchEntryValue()).thenReturn(udpSrcCaseValue);
87 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = udpSrcConvertor.convert(matchEntry,
88 MatchPath.PACKET_RECEIVED_MATCH);
89 Assert.assertEquals(Integer.valueOf(2),
90 ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmOfUdpSrc().getMask());
91 Assert.assertEquals(DEFAULT_PORT,
92 ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmOfUdpSrc().getPort());
93 Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpSrcKey.class);
95 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = udpSrcConvertor
96 .convert(matchEntry, MatchPath.SWITCH_FLOW_REMOVED_MATCH);
97 Assert.assertEquals(Integer.valueOf(2),
98 ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject()).getNxmOfUdpSrc()
100 Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
101 .getNxmOfUdpSrc().getPort());
102 Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpSrcKey.class);
104 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = udpSrcConvertor
105 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
106 Assert.assertEquals(Integer.valueOf(2),
107 ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject()).getNxmOfUdpSrc().getMask());
108 Assert.assertEquals(DEFAULT_PORT,
109 ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject()).getNxmOfUdpSrc().getPort());
110 Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpSrcKey.class);
112 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = udpSrcConvertor
113 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_RPC_MATCH);
114 Assert.assertEquals(Integer.valueOf(2),
115 ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmOfUdpSrc().getMask());
116 Assert.assertEquals(DEFAULT_PORT,
117 ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmOfUdpSrc().getPort());
118 Assert.assertEquals(extensionAugment.getKey(), NxmOfUdpSrcKey.class);