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
8 package org.opendaylight.openflowplugin.openflow.md.core.extension;
10 import java.util.ArrayList;
11 import java.util.Collection;
12 import java.util.List;
13 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
14 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
15 import org.opendaylight.openflowplugin.extension.api.AugmentTuple;
16 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
17 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
18 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
19 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
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.openflowplugin.extension.general.rev140714.GeneralAugMatchNotifPacketIn;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNotifPacketInBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNotifSwitchFlowRemoved;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNotifSwitchFlowRemovedBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNotifUpdateFlowStats;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNotifUpdateFlowStatsBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match;
34 import org.opendaylight.yangtools.yang.binding.Augmentable;
35 import org.opendaylight.yangtools.yang.binding.Augmentation;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
42 public final class MatchExtensionHelper {
44 private static final Logger LOG = LoggerFactory
45 .getLogger(MatchExtensionHelper.class);
47 private MatchExtensionHelper() {
48 throw new IllegalAccessError("singleton enforcement");
52 * @param matchEntries match entries
53 * @param ofVersion openflow version
54 * @param matchPath match path
55 * @param <EXT_POINT> extension point
56 * @return augmentation wrapper containing augmentation depending on matchPath
58 @SuppressWarnings("unchecked")
59 public static <EXT_POINT extends Augmentable<EXT_POINT>>
60 AugmentTuple<EXT_POINT> processAllExtensions(Collection<MatchEntry> matchEntries,
61 OpenflowVersion ofVersion, MatchPath matchPath) {
62 List<ExtensionList> extensionsList = new ArrayList<>();
64 for (MatchEntry matchEntry : matchEntries) {
65 ExtensionListBuilder extensionListBld = processExtension(matchEntry, ofVersion, matchPath);
66 if (extensionListBld == null) {
70 extensionsList.add(extensionListBld.build());
73 AugmentTuple<EXT_POINT> augmentTuple = null;
74 if (!extensionsList.isEmpty()) {
76 case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH:
77 GeneralAugMatchNotifUpdateFlowStatsBuilder generalExtMatchAugBld1 = new GeneralAugMatchNotifUpdateFlowStatsBuilder();
78 generalExtMatchAugBld1.setExtensionList(extensionsList);
79 augmentTuple = (AugmentTuple<EXT_POINT>)
80 new AugmentTuple<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match>(
81 GeneralAugMatchNotifUpdateFlowStats.class, generalExtMatchAugBld1.build());
83 case PACKETRECEIVED_MATCH:
84 GeneralAugMatchNotifPacketInBuilder generalExtMatchAugBld2 = new GeneralAugMatchNotifPacketInBuilder();
85 generalExtMatchAugBld2.setExtensionList(extensionsList);
86 augmentTuple = (AugmentTuple<EXT_POINT>)
87 new AugmentTuple<Match>(GeneralAugMatchNotifPacketIn.class, generalExtMatchAugBld2.build());
89 case SWITCHFLOWREMOVED_MATCH:
90 GeneralAugMatchNotifSwitchFlowRemovedBuilder generalExtMatchAugBld3 = new GeneralAugMatchNotifSwitchFlowRemovedBuilder();
91 generalExtMatchAugBld3.setExtensionList(extensionsList);
92 augmentTuple = (AugmentTuple<EXT_POINT>)
93 new AugmentTuple<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.mod.removed.Match>(
94 GeneralAugMatchNotifSwitchFlowRemoved.class, generalExtMatchAugBld3.build());
97 LOG.warn("matchPath not supported: {}", matchPath);
110 private static ExtensionListBuilder processExtension(MatchEntry matchEntry, OpenflowVersion ofVersion, MatchPath matchPath) {
111 ExtensionListBuilder extListBld = null;
113 /** TODO: EXTENSION PROPOSAL (match, OFJava to MD-SAL) */
114 MatchEntrySerializerKey<? extends OxmClassBase, ? extends MatchField> key = new MatchEntrySerializerKey<>(
115 ofVersion.getVersion(), matchEntry.getOxmClass(), matchEntry.getOxmMatchField());
116 if (null != OFSessionUtil.getExtensionConvertorProvider()) {
117 ConvertorFromOFJava<MatchEntry, MatchPath> convertor = OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
118 if (convertor != null) {
119 ExtensionAugment<? extends Augmentation<Extension>> extensionMatch =
120 convertor.convert(matchEntry, matchPath);
121 ExtensionBuilder extBld = new ExtensionBuilder();
122 extBld.addAugmentation(extensionMatch.getAugmentationClass(), extensionMatch.getAugmentationObject());
124 extListBld = new ExtensionListBuilder();
125 extListBld.setExtension(extBld.build());
126 extListBld.setExtensionKey(extensionMatch.getKey());