2 * Copyright (c) 2015 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.impl.statistics.services;
10 import com.google.common.annotations.VisibleForTesting;
11 import com.google.common.base.Preconditions;
12 import java.util.ArrayList;
13 import java.util.List;
14 import java.util.concurrent.atomic.AtomicLong;
15 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
16 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
17 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
18 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
19 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdated;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdatedBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Chaining;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.ChainingChecks;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupAll;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupCapability;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupFf;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupIndirect;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupSelect;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupType;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.SelectLiveness;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.SelectWeight;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupCapabilities;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupTypes;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupFeaturesCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.features._case.MultipartReplyGroupFeatures;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder;
48 final class GroupFeaturesService
49 extends AbstractCompatibleStatService<GetGroupFeaturesInput, GetGroupFeaturesOutput, GroupFeaturesUpdated> {
51 private static final MultipartRequestGroupFeaturesCase GROUP_FEAT_CASE =
52 new MultipartRequestGroupFeaturesCaseBuilder().build();
54 public GroupFeaturesService(RequestContextStack requestContextStack, DeviceContext deviceContext, AtomicLong compatibilityXidSeed) {
55 super(requestContextStack, deviceContext, compatibilityXidSeed);
59 protected OfHeader buildRequest(final Xid xid, final GetGroupFeaturesInput input) {
60 final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
61 MultipartType.OFPMPGROUPFEATURES, xid.getValue(), getVersion());
62 mprInput.setMultipartRequestBody(GROUP_FEAT_CASE);
63 return mprInput.build();
67 public GetGroupFeaturesOutput buildTxCapableResult(TransactionId emulatedTxId) {
68 return new GetGroupFeaturesOutputBuilder().setTransactionId(emulatedTxId).build();
72 public GroupFeaturesUpdated transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
73 final int mpSize = result.size();
74 Preconditions.checkArgument(mpSize == 1, "unexpected (!=1) mp-reply size received: {}", mpSize);
76 GroupFeaturesUpdatedBuilder notification = new GroupFeaturesUpdatedBuilder();
77 notification.setId(getDeviceInfo().getNodeId());
78 notification.setMoreReplies(Boolean.FALSE);
79 notification.setTransactionId(emulatedTxId);
81 MultipartReplyGroupFeaturesCase caseBody = (MultipartReplyGroupFeaturesCase) result.get(0).getMultipartReplyBody();
82 MultipartReplyGroupFeatures replyBody = caseBody.getMultipartReplyGroupFeatures();
84 notification.setGroupTypesSupported(extractSupportedGroupTypes(replyBody.getTypes()));
85 notification.setMaxGroups(replyBody.getMaxGroups());
86 notification.setGroupCapabilitiesSupported(extractSupportedCapabilities(replyBody.getCapabilities()));
87 notification.setActions(extractGroupActionsSupportBitmap(replyBody.getActionsBitmap()));
89 return notification.build();
93 static List<Class<? extends GroupCapability>> extractSupportedCapabilities(GroupCapabilities capabilities) {
94 List<Class<? extends GroupCapability>> supportedCapabilities = new ArrayList<>();
96 if (capabilities.isOFPGFCCHAINING()) {
97 supportedCapabilities.add(Chaining.class);
99 if (capabilities.isOFPGFCCHAININGCHECKS()) {
100 supportedCapabilities.add(ChainingChecks.class);
102 if (capabilities.isOFPGFCSELECTLIVENESS()) {
103 supportedCapabilities.add(SelectLiveness.class);
105 if (capabilities.isOFPGFCSELECTWEIGHT()) {
106 supportedCapabilities.add(SelectWeight.class);
108 return supportedCapabilities;
112 static List<Class<? extends GroupType>> extractSupportedGroupTypes(GroupTypes types) {
113 List<Class<? extends GroupType>> supportedGroups = new ArrayList<>();
115 if (types.isOFPGTALL()) {
116 supportedGroups.add(GroupAll.class);
118 if (types.isOFPGTSELECT()) {
119 supportedGroups.add(GroupSelect.class);
121 if (types.isOFPGTINDIRECT()) {
122 supportedGroups.add(GroupIndirect.class);
124 if (types.isOFPGTFF()) {
125 supportedGroups.add(GroupFf.class);
127 return supportedGroups;
131 static List<Long> extractGroupActionsSupportBitmap(final List<ActionType> actionsSupported) {
132 List<Long> supportActionByGroups = new ArrayList<>();
133 for (ActionType supportedActions : actionsSupported) {
134 long supportActionBitmap = 0;
135 supportActionBitmap |= supportedActions.isOFPATOUTPUT() ? (1 << 0) : 0;
136 supportActionBitmap |= supportedActions.isOFPATCOPYTTLOUT() ? (1 << 11) : 0;
137 supportActionBitmap |= supportedActions.isOFPATCOPYTTLIN() ? (1 << 12) : 0;
138 supportActionBitmap |= supportedActions.isOFPATSETMPLSTTL() ? (1 << 15) : 0;
139 supportActionBitmap |= supportedActions.isOFPATDECMPLSTTL() ? (1 << 16) : 0;
140 supportActionBitmap |= supportedActions.isOFPATPUSHVLAN() ? (1 << 17) : 0;
141 supportActionBitmap |= supportedActions.isOFPATPOPVLAN() ? (1 << 18) : 0;
142 supportActionBitmap |= supportedActions.isOFPATPUSHMPLS() ? (1 << 19) : 0;
143 supportActionBitmap |= supportedActions.isOFPATPOPMPLS() ? (1 << 20) : 0;
144 supportActionBitmap |= supportedActions.isOFPATSETQUEUE() ? (1 << 21) : 0;
145 supportActionBitmap |= supportedActions.isOFPATGROUP() ? (1 << 22) : 0;
146 supportActionBitmap |= supportedActions.isOFPATSETNWTTL() ? (1 << 23) : 0;
147 supportActionBitmap |= supportedActions.isOFPATDECNWTTL() ? (1 << 24) : 0;
148 supportActionBitmap |= supportedActions.isOFPATSETFIELD() ? (1 << 25) : 0;
149 supportActionBitmap |= supportedActions.isOFPATPUSHPBB() ? (1 << 26) : 0;
150 supportActionBitmap |= supportedActions.isOFPATPOPPBB() ? (1 << 27) : 0;
151 supportActionByGroups.add(Long.valueOf(supportActionBitmap));
153 return supportActionByGroups;