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.action;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionConntrack;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionConntrackBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.NxActionConntrackBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flows.statistics.update.flow.and.statistics.map.list.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionConntrackNotifFlowsStatisticsUpdateApplyActionsCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flows.statistics.update.flow.and.statistics.map.list.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionConntrackNotifFlowsStatisticsUpdateWriteActionsCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.group.desc.stats.updated.group.desc.stats.buckets.bucket.action.action.NxActionConntrackNotifGroupDescStatsUpdatedCase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionConntrackNodesNodeTableFlowWriteActionsCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionConntrackNodesNodeTableFlowWriteActionsCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.conntrack.grouping.NxConntrackBuilder;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * Test for {@link ConntrackConvertor}.
32 public class ConntrackConvertorTest {
34 private static final Logger LOG = LoggerFactory.getLogger(ConntrackConvertorTest.class);
36 private ConntrackConvertor conntrackConvertor;
39 public void setUp() throws Exception {
40 conntrackConvertor = new ConntrackConvertor();
44 public void testConvertToOFJava() throws Exception {
46 final NxConntrackBuilder nxConntrackBuilder = new NxConntrackBuilder()
49 .setRecircTable((short) 1)
52 final NxActionConntrackNodesNodeTableFlowWriteActionsCaseBuilder nxActionConntrackBuilder =
53 new NxActionConntrackNodesNodeTableFlowWriteActionsCaseBuilder()
54 .setNxConntrack(nxConntrackBuilder.build());
56 final NxActionConntrackNodesNodeTableFlowWriteActionsCase actionsCase = nxActionConntrackBuilder.build();
57 final ActionConntrack actionConntrack = (ActionConntrack) conntrackConvertor.convert(actionsCase).getActionChoice();
59 Assert.assertEquals(actionsCase.getNxConntrack().getConntrackZone(), actionConntrack.getNxActionConntrack().getConntrackZone());
60 Assert.assertEquals(actionsCase.getNxConntrack().getFlags(), actionConntrack.getNxActionConntrack().getFlags());
61 Assert.assertEquals(actionsCase.getNxConntrack().getRecircTable(), actionConntrack.getNxActionConntrack().getRecircTable());
62 Assert.assertEquals(actionsCase.getNxConntrack().getZoneSrc(), actionConntrack.getNxActionConntrack().getZoneSrc());
66 public void testConvertFromOFJava() throws Exception {
67 final NxActionConntrackBuilder nxActionConntrackBuilder = new NxActionConntrackBuilder()
70 .setRecircTable((short) 1)
73 final ActionConntrackBuilder actionConntrackBuilder = new ActionConntrackBuilder()
74 .setNxActionConntrack(nxActionConntrackBuilder.build());
76 final ActionBuilder actionBuilder = new ActionBuilder()
77 .setActionChoice(actionConntrackBuilder.build());
79 final Action groupingAction = actionBuilder.build();
81 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action
82 = conntrackConvertor.convert(groupingAction, ActionPath.NODES_NODE_TABLE_FLOW_INSTRUCTIONS_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION_EXTENSIONLIST_EXTENSION);
83 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action1
84 = conntrackConvertor.convert(groupingAction, ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION);
85 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action2
86 = conntrackConvertor.convert(groupingAction, ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION);
87 final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action3
88 = conntrackConvertor.convert(groupingAction, ActionPath.GROUPDESCSTATSUPDATED_GROUPDESCSTATS_BUCKETS_BUCKET_ACTION);
90 Assert.assertEquals(1, ((NxActionConntrackNodesNodeTableFlowWriteActionsCase) action).getNxConntrack().getConntrackZone().longValue());
91 Assert.assertEquals(1L, ((NxActionConntrackNodesNodeTableFlowWriteActionsCase) action).getNxConntrack().getZoneSrc().longValue());
92 Assert.assertEquals(1, ((NxActionConntrackNodesNodeTableFlowWriteActionsCase) action).getNxConntrack().getRecircTable().intValue());
93 Assert.assertEquals(1, ((NxActionConntrackNodesNodeTableFlowWriteActionsCase) action).getNxConntrack().getFlags().intValue());
95 Assert.assertEquals(1, ((NxActionConntrackNotifFlowsStatisticsUpdateWriteActionsCase) action1).getNxConntrack().getConntrackZone().longValue());
96 Assert.assertEquals(1L, ((NxActionConntrackNotifFlowsStatisticsUpdateWriteActionsCase) action1).getNxConntrack().getZoneSrc().longValue());
97 Assert.assertEquals(1, ((NxActionConntrackNotifFlowsStatisticsUpdateWriteActionsCase) action1).getNxConntrack().getRecircTable().intValue());
98 Assert.assertEquals(1, ((NxActionConntrackNotifFlowsStatisticsUpdateWriteActionsCase) action1).getNxConntrack().getFlags().intValue());
100 Assert.assertEquals(1, ((NxActionConntrackNotifFlowsStatisticsUpdateApplyActionsCase) action2).getNxConntrack().getConntrackZone().longValue());
101 Assert.assertEquals(1L, ((NxActionConntrackNotifFlowsStatisticsUpdateApplyActionsCase) action2).getNxConntrack().getZoneSrc().longValue());
102 Assert.assertEquals(1, ((NxActionConntrackNotifFlowsStatisticsUpdateApplyActionsCase) action2).getNxConntrack().getRecircTable().intValue());
103 Assert.assertEquals(1, ((NxActionConntrackNotifFlowsStatisticsUpdateApplyActionsCase) action2).getNxConntrack().getFlags().intValue());
105 Assert.assertEquals(1, ((NxActionConntrackNotifGroupDescStatsUpdatedCase) action3).getNxConntrack().getConntrackZone().longValue());
106 Assert.assertEquals(1L, ((NxActionConntrackNotifGroupDescStatsUpdatedCase) action3).getNxConntrack().getZoneSrc().longValue());
107 Assert.assertEquals(1, ((NxActionConntrackNotifGroupDescStatsUpdatedCase) action3).getNxConntrack().getRecircTable().intValue());
108 Assert.assertEquals(1, ((NxActionConntrackNotifGroupDescStatsUpdatedCase) action3).getNxConntrack().getFlags().intValue());