2 * Copyright (c) 2014 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.openflow.md.core.extension;
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.Mockito.when;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.MockitoAnnotations.Mock;
18 import org.mockito.runners.MockitoJUnitRunner;
19 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
20 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
21 import org.opendaylight.openflowplugin.extension.api.AugmentTuple;
22 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
23 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
24 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
25 import org.opendaylight.openflowplugin.extension.api.path.AugmentationPath;
26 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
27 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
35 import org.opendaylight.yangtools.yang.binding.DataContainer;
36 import java.util.ArrayList;
37 import java.util.List;
40 * Created by Martin Bobak mbobak@cisco.com on 9/19/14.
42 @RunWith(MockitoJUnitRunner.class)
43 public class MatchExtensionHelperTest {
46 private ExtensionConverterProvider extensionConverterProvider;
47 private static final int PRESET_COUNT = 7;
48 private static final MatchEntrySerializerKey<? extends OxmClassBase, ? extends MatchField> key = new MatchEntrySerializerKey<>(OpenflowVersion.OF13.getVersion(), MockOxmClassBase.class, MockMatchField.class);
52 OFSessionUtil.getSessionManager().setExtensionConverterProvider(extensionConverterProvider);
53 when(extensionConverterProvider.getConverter(key)).thenReturn(new ConvertorFromOFJava<DataContainer, AugmentationPath>() {
55 public ExtensionAugment<? extends Augmentation<Extension>> convert(DataContainer input, AugmentationPath path) {
56 MockAugmentation mockAugmentation = new MockAugmentation();
57 return new ExtensionAugment(MockAugmentation.class, mockAugmentation, MockExtensionKey.class);
65 * Basic functionality test method for {@link org.opendaylight.openflowplugin.openflow.md.core.extension.MatchExtensionHelper#processAllExtensions(java.util.Collection, org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion, org.opendaylight.openflowplugin.extension.api.path.MatchPath)}
67 public void testProcessAllExtensions() {
69 List<MatchEntry> matchEntries = createMatchEntrieses();
70 AugmentTuple augmentTuple = MatchExtensionHelper.processAllExtensions(matchEntries, OpenflowVersion.OF13, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
71 assertNotNull(augmentTuple);
73 augmentTuple = MatchExtensionHelper.processAllExtensions(matchEntries, OpenflowVersion.OF13, MatchPath.PACKETRECEIVED_MATCH);
74 assertNotNull(augmentTuple);
76 augmentTuple = MatchExtensionHelper.processAllExtensions(matchEntries, OpenflowVersion.OF13, MatchPath.SWITCHFLOWREMOVED_MATCH);
77 assertNotNull(augmentTuple);
81 private List<MatchEntry> createMatchEntrieses() {
82 List<MatchEntry> matchEntries = new ArrayList<>();
83 for (int i = 0; i < PRESET_COUNT; i++) {
84 MatchEntryBuilder MatchEntryBuilder = new MatchEntryBuilder();
85 MatchEntryBuilder.setHasMask(true);
86 MatchEntryBuilder.setOxmClass(MockOxmClassBase.class);
87 MatchEntryBuilder.setOxmMatchField(MockMatchField.class);
88 matchEntries.add(MatchEntryBuilder.build());
93 private static final class MockOxmClassBase extends OxmClassBase {
97 private static final class MockMatchField extends MatchField {
101 private final class MockExtensionKey extends ExtensionKey {
105 private final class MockAugmentation implements Augmentation<Extension> {