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