2 * Copyright (c) 2019 Ericsson India Global Services Pvt Ltd. 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.eric.convertor.match;
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Mockito.when;
14 import java.util.Collections;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Matchers;
20 import org.mockito.Mock;
21 import org.mockito.junit.MockitoJUnitRunner;
22 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
23 import org.opendaylight.openflowplugin.extension.api.GroupingLooseResolver;
24 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.icmpv6.nd.options.type.grouping.Icmpv6NdOptionsTypeValuesBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.oxm.container.match.entry.value.Icmpv6NdOptionsTypeCaseValue;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.oxm.container.match.entry.value.Icmpv6NdOptionsTypeCaseValueBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNodesNodeTableFlow;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNodesNodeTableFlowBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifPacketIn;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifSwitchFlowRemoved;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchRpcGetFlowStats;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.Icmpv6NdOptionsTypeKey;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.eric.of.icmpv6.nd.options.type.grouping.EricOfIcmpv6NdOptionsTypeBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowWriteActionsSetField;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionListGrouping;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
44 import org.opendaylight.yangtools.yang.binding.Augmentation;
47 * Test for {@link Icmpv6NDOptionsTypeConvertor}.
49 @RunWith(MockitoJUnitRunner.class)
50 public class Icmpv6NDOptionsTypeConvertorTest {
53 private Extension extension;
55 private MatchEntry matchEntry;
57 private Icmpv6NDOptionsTypeConvertor icmpv6NDOptionsTypeConvertor;
61 final EricOfIcmpv6NdOptionsTypeBuilder ericOfIcmpv6NdOptionsTypeBuilder = new EricOfIcmpv6NdOptionsTypeBuilder()
62 .setIcmpv6NdOptionsType((short)1);
63 final EricAugMatchNodesNodeTableFlowBuilder ericAugMatchNotifUpdateFlowStatsBuilder =
64 new EricAugMatchNodesNodeTableFlowBuilder();
65 ericAugMatchNotifUpdateFlowStatsBuilder.setEricOfIcmpv6NdOptionsType(ericOfIcmpv6NdOptionsTypeBuilder.build());
67 final Augmentation<Extension> extensionAugmentation = ericAugMatchNotifUpdateFlowStatsBuilder.build();
68 when(extension.augmentation(Matchers.any()))
69 .thenReturn(extensionAugmentation);
71 icmpv6NDOptionsTypeConvertor = new Icmpv6NDOptionsTypeConvertor();
75 public void testConvert() {
76 final MatchEntry converted = icmpv6NDOptionsTypeConvertor.convert(extension);
77 assertEquals(1, ((Icmpv6NdOptionsTypeCaseValue)converted.getMatchEntryValue())
78 .getIcmpv6NdOptionsTypeValues().getIcmpv6NdOptionsType().intValue());
82 public void testConvert1() {
83 final Icmpv6NdOptionsTypeValuesBuilder icmpv6NdOptionsTypeValuesBuilder = new Icmpv6NdOptionsTypeValuesBuilder()
84 .setIcmpv6NdOptionsType((short)10);
85 final Icmpv6NdOptionsTypeCaseValueBuilder icmpv6NdOptionsTypeCaseValueBuilder
86 = new Icmpv6NdOptionsTypeCaseValueBuilder()
87 .setIcmpv6NdOptionsTypeValues(icmpv6NdOptionsTypeValuesBuilder.build());
89 final Icmpv6NdOptionsTypeCaseValue icmpv6NdOptionsTypeCaseValue = icmpv6NdOptionsTypeCaseValueBuilder.build();
90 when(matchEntry.getMatchEntryValue()).thenReturn(icmpv6NdOptionsTypeCaseValue);
92 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment
93 = icmpv6NDOptionsTypeConvertor.convert(matchEntry, MatchPath.PACKET_RECEIVED_MATCH);
94 assertEquals(10, ((EricAugMatchNotifPacketIn) extensionAugment.getAugmentationObject())
95 .getEricOfIcmpv6NdOptionsType().getIcmpv6NdOptionsType().intValue());
96 assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.class);
98 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1
99 = icmpv6NDOptionsTypeConvertor.convert(matchEntry, MatchPath.SWITCH_FLOW_REMOVED_MATCH);
100 assertEquals(10, ((EricAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
101 .getEricOfIcmpv6NdOptionsType() .getIcmpv6NdOptionsType().intValue());
102 assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.class);
104 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2
105 = icmpv6NDOptionsTypeConvertor.convert(matchEntry, MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
106 assertEquals(10, ((EricAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
107 .getEricOfIcmpv6NdOptionsType().getIcmpv6NdOptionsType().intValue());
108 assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.class);
110 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3
111 = icmpv6NDOptionsTypeConvertor.convert(matchEntry, MatchPath.FLOWS_STATISTICS_RPC_MATCH);
112 assertEquals(10, ((EricAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject())
113 .getEricOfIcmpv6NdOptionsType().getIcmpv6NdOptionsType().intValue());
114 assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.class);
118 public void testSetFieldExtension() {
119 GroupingLooseResolver<GeneralExtensionListGrouping> eqGroup =
120 new GroupingLooseResolver<>(GeneralExtensionListGrouping.class);
121 eqGroup.add(GeneralAugMatchNodesNodeTableFlowWriteActionsSetField.class);
123 ExtensionAugment<? extends Augmentation<Extension>> extensionMatch
124 = new ExtensionAugment<>(EricAugMatchNodesNodeTableFlow.class,
125 new EricAugMatchNodesNodeTableFlowBuilder().setEricOfIcmpv6NdOptionsType(
126 new EricOfIcmpv6NdOptionsTypeBuilder().setIcmpv6NdOptionsType((short)1).build()).build(),
127 Icmpv6NdOptionsTypeKey.class);
129 ExtensionListBuilder extListBld = null;
130 ExtensionBuilder extBld = new ExtensionBuilder();
131 extBld.addAugmentation(extensionMatch.getAugmentationClass(), extensionMatch.getAugmentationObject());
133 extListBld = new ExtensionListBuilder();
134 extListBld.setExtension(extBld.build());
135 extListBld.setExtensionKey(extensionMatch.getKey());
137 GeneralAugMatchNodesNodeTableFlowWriteActionsSetField ndOptionsTypeSetField =
138 new GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder()
139 .setExtensionList(Collections.singletonList(extListBld.build())).build();
141 SetFieldBuilder sb = new SetFieldBuilder();
142 SetField setField = sb.addAugmentation(GeneralAugMatchNodesNodeTableFlowWriteActionsSetField.class,
143 ndOptionsTypeSetField).build();
145 Assert.assertEquals(Icmpv6NdOptionsTypeKey.class, eqGroup.getExtension(setField).get().getExtensionList().get(0)