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.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.state.grouping.CtStateValuesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtStateCaseValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtStateCaseValueBuilder;
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.NxmNxCtStateKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.state.grouping.NxmNxCtStateBuilder;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
37 * Test for {@link CtStateConvertor}.
39 @RunWith(MockitoJUnitRunner.class)
40 public class CtStateConvertorTest {
43 private Extension extension;
45 private MatchEntry matchEntry;
47 private CtStateConvertor ctStateConvertor;
50 public void setUp() throws Exception {
52 final NxmNxCtStateBuilder nxmNxCtStateBuilder = new NxmNxCtStateBuilder()
55 final NxAugMatchNodesNodeTableFlowBuilder nxAugMatchNotifUpdateFlowStatsBuilder =
56 new NxAugMatchNodesNodeTableFlowBuilder();
57 nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxCtState(nxmNxCtStateBuilder.build());
59 final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
60 when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any()))
61 .thenReturn(extensionAugmentation);
63 ctStateConvertor = new CtStateConvertor();
67 public void testConvert() throws Exception {
68 final MatchEntry converted = ctStateConvertor.convert(extension);
69 Assert.assertEquals(1L,
70 ((CtStateCaseValue) converted.getMatchEntryValue()).getCtStateValues().getCtState().longValue());
71 Assert.assertEquals(2L,
72 ((CtStateCaseValue) converted.getMatchEntryValue()).getCtStateValues().getMask().longValue());
76 public void testConvert1() throws Exception {
78 final CtStateValuesBuilder ctStateValuesBuilder = new CtStateValuesBuilder()
81 final CtStateCaseValueBuilder ctStateCaseValueBuilder = new CtStateCaseValueBuilder()
82 .setCtStateValues(ctStateValuesBuilder.build());
84 final CtStateCaseValue ctStateCaseValue = ctStateCaseValueBuilder.build();
86 when(matchEntry.getMatchEntryValue()).thenReturn(ctStateCaseValue);
88 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = ctStateConvertor
89 .convert(matchEntry, MatchPath.PACKET_RECEIVED_MATCH);
90 Assert.assertEquals(3L, ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxCtState()
91 .getCtState().longValue());
92 Assert.assertEquals(4L, ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxCtState()
93 .getMask().longValue());
94 Assert.assertEquals(extensionAugment.getKey(), NxmNxCtStateKey.class);
96 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = ctStateConvertor
97 .convert(matchEntry, MatchPath.SWITCH_FLOW_REMOVED_MATCH);
98 Assert.assertEquals(3L, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
99 .getNxmNxCtState().getCtState().longValue());
100 Assert.assertEquals(4L, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
101 .getNxmNxCtState().getMask().longValue());
102 Assert.assertEquals(extensionAugment.getKey(), NxmNxCtStateKey.class);
104 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = ctStateConvertor
105 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
106 Assert.assertEquals(3L, ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
107 .getNxmNxCtState().getCtState().longValue());
108 Assert.assertEquals(4L, ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
109 .getNxmNxCtState().getMask().longValue());
110 Assert.assertEquals(extensionAugment.getKey(), NxmNxCtStateKey.class);
112 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = ctStateConvertor
113 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_RPC_MATCH);
114 Assert.assertEquals(3L, ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject())
115 .getNxmNxCtState().getCtState().longValue());
116 Assert.assertEquals(4L, ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject())
117 .getNxmNxCtState().getMask().longValue());
118 Assert.assertEquals(extensionAugment.getKey(), NxmNxCtStateKey.class);