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.inet.types.rev100924.PortNumber;
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.of.match.tcp.src.grouping.TcpSrcValuesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpSrcCaseValue;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpSrcCaseValueBuilder;
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.NxAugMatchNotifUpdateFlowStatsBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfTcpSrcKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.tcp.src.grouping.NxmOfTcpSrcBuilder;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
37 * Test for {@link TcpSrcConvertor}.
39 @RunWith(MockitoJUnitRunner.class)
40 public class TcpSrcConvertorTest {
42 private Extension extension;
44 private MatchEntry matchEntry;
46 private static final PortNumber DEFAULT_PORT = new PortNumber(9999);
48 private TcpSrcConvertor tcpSrcConvertor;
51 public void setUp() throws Exception {
52 final NxmOfTcpSrcBuilder nxmOfTcpSrcBuilder = new NxmOfTcpSrcBuilder()
54 .setPort(DEFAULT_PORT);
55 final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
56 nxAugMatchNotifUpdateFlowStatsBuilder.setNxmOfTcpSrc(nxmOfTcpSrcBuilder.build());
58 final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
59 when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
61 tcpSrcConvertor = new TcpSrcConvertor();
65 public void testConvert() throws Exception {
66 final MatchEntry matchEntry = tcpSrcConvertor.convert(extension);
67 Assert.assertEquals(1, ((TcpSrcCaseValue)matchEntry.getMatchEntryValue()).getTcpSrcValues().getMask().intValue());
68 Assert.assertEquals(DEFAULT_PORT, ((TcpSrcCaseValue)matchEntry.getMatchEntryValue()).getTcpSrcValues().getPort());
72 public void testConvert1() throws Exception {
73 final TcpSrcValuesBuilder tcpSrcValuesBuilder = new TcpSrcValuesBuilder()
75 .setPort(DEFAULT_PORT);
76 final TcpSrcCaseValueBuilder tcpSrcCaseValueBuilder = new TcpSrcCaseValueBuilder()
77 .setTcpSrcValues(tcpSrcValuesBuilder.build());
79 final TcpSrcCaseValue tcpSrcCaseValue = tcpSrcCaseValueBuilder.build();
81 when(matchEntry.getMatchEntryValue()).thenReturn(tcpSrcCaseValue);
83 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = tcpSrcConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
84 Assert.assertEquals(2, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfTcpSrc().getMask().intValue());
85 Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmOfTcpSrc().getPort());
86 Assert.assertEquals(extensionAugment.getKey(), NxmOfTcpSrcKey.class);
88 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = tcpSrcConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
89 Assert.assertEquals(2, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfTcpSrc().getMask().intValue());
90 Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmOfTcpSrc().getPort());
91 Assert.assertEquals(extensionAugment.getKey(), NxmOfTcpSrcKey.class);
93 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = tcpSrcConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
94 Assert.assertEquals(2, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfTcpSrc().getMask().intValue());
95 Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmOfTcpSrc().getPort());
96 Assert.assertEquals(extensionAugment.getKey(), NxmOfTcpSrcKey.class);