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.rev130715.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.dst.grouping.TcpDstValuesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpDstCaseValue;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpDstCaseValueBuilder;
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.NxAugMatchNodesNodeTableFlowBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
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.NxmOfTcpDstKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.tcp.dst.grouping.NxmOfTcpDstBuilder;
35 import org.opendaylight.yangtools.yang.binding.Augmentation;
38 * Test for {@link TcpDstConvertor}.
40 @RunWith(MockitoJUnitRunner.class)
41 public class TcpDstConvertorTest {
43 private Extension extension;
45 private MatchEntry matchEntry;
47 private static final PortNumber DEFAULT_PORT = new PortNumber(9999);
49 private TcpDstConvertor tcpDstConvertor;
52 public void setUp() throws Exception {
53 final NxmOfTcpDstBuilder nxmOfTcpDstBuilder = new NxmOfTcpDstBuilder()
55 .setPort(DEFAULT_PORT);
56 final NxAugMatchNodesNodeTableFlowBuilder nxAugMatchNotifUpdateFlowStatsBuilder =
57 new NxAugMatchNodesNodeTableFlowBuilder();
58 nxAugMatchNotifUpdateFlowStatsBuilder.setNxmOfTcpDst(nxmOfTcpDstBuilder.build());
60 final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
61 when(extension.augmentation(Matchers.<Class<Augmentation<Extension>>>any()))
62 .thenReturn(extensionAugmentation);
64 tcpDstConvertor = new TcpDstConvertor();
68 public void testConvert() throws Exception {
69 final MatchEntry converted = tcpDstConvertor.convert(extension);
70 Assert.assertEquals(1,
71 ((TcpDstCaseValue) converted.getMatchEntryValue()).getTcpDstValues().getMask().intValue());
72 Assert.assertEquals(DEFAULT_PORT,
73 ((TcpDstCaseValue) converted.getMatchEntryValue()).getTcpDstValues().getPort());
77 public void testConvert1() throws Exception {
78 final TcpDstValuesBuilder tcpDstValuesBuilder = new TcpDstValuesBuilder()
80 .setPort(DEFAULT_PORT);
81 final TcpDstCaseValueBuilder tcpDstCaseValueBuilder = new TcpDstCaseValueBuilder()
82 .setTcpDstValues(tcpDstValuesBuilder.build());
84 final TcpDstCaseValue tcpDstCaseValue = tcpDstCaseValueBuilder.build();
86 when(matchEntry.getMatchEntryValue()).thenReturn(tcpDstCaseValue);
88 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = tcpDstConvertor.convert(matchEntry,
89 MatchPath.PACKET_RECEIVED_MATCH);
90 Assert.assertEquals(2, ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmOfTcpDst()
91 .getMask().intValue());
92 Assert.assertEquals(DEFAULT_PORT,
93 ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmOfTcpDst().getPort());
94 Assert.assertEquals(extensionAugment.getKey(), NxmOfTcpDstKey.class);
96 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = tcpDstConvertor
97 .convert(matchEntry, MatchPath.SWITCH_FLOW_REMOVED_MATCH);
98 Assert.assertEquals(2, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
99 .getNxmOfTcpDst().getMask().intValue());
100 Assert.assertEquals(DEFAULT_PORT, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
101 .getNxmOfTcpDst().getPort());
102 Assert.assertEquals(extensionAugment.getKey(), NxmOfTcpDstKey.class);
104 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = tcpDstConvertor
105 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
106 Assert.assertEquals(2, ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
107 .getNxmOfTcpDst().getMask().intValue());
108 Assert.assertEquals(DEFAULT_PORT,
109 ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject()).getNxmOfTcpDst().getPort());
110 Assert.assertEquals(extensionAugment.getKey(), NxmOfTcpDstKey.class);
112 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = tcpDstConvertor
113 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_RPC_MATCH);
114 Assert.assertEquals(2, ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmOfTcpDst()
115 .getMask().intValue());
116 Assert.assertEquals(DEFAULT_PORT,
117 ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmOfTcpDst().getPort());
118 Assert.assertEquals(extensionAugment.getKey(), NxmOfTcpDstKey.class);