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.groupbasedpolicy.renderer.ofoverlay.sf;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.HashMap;
14 import java.util.List;
17 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
18 import org.opendaylight.groupbasedpolicy.sf.classifiers.EtherTypeClassifierDefinition;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
22 public abstract class ParamDerivator {
25 * It is possible to derive missing parameters.
29 * Ether-type parameter is missing. Derivation policy might instruct: ipv4 and ipv6 flows need
30 * to be created if ether-type parameter is not present. In this case two derivations of
31 * {@code params} should be returned. One with ipv4 ether-type, the other with ipv6.
33 * @param params parameters inserted by user
34 * @return list of {@code params} updated with derived values
36 public abstract List<Map<String, ParameterValue>> deriveParameter(Map<String, ParameterValue> params);
38 public static final ParamDerivator ETHER_TYPE_DERIVATOR = new ParamDerivator() {
41 public List<Map<String, ParameterValue>> deriveParameter(Map<String, ParameterValue> params) {
43 if (!params.containsKey(EtherTypeClassifierDefinition.ETHERTYPE_PARAM)) {
44 Map<String, ParameterValue> ipv4Params = new HashMap<>(params);
45 Map<String, ParameterValue> ipv6Params = new HashMap<>(params);
46 ipv4Params.put(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, new ParameterValueBuilder().setIntValue(FlowUtils.IPv4)
48 ipv6Params.put(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, new ParameterValueBuilder().setIntValue(FlowUtils.IPv6)
50 List<Map<String, ParameterValue>> derivedParams = new ArrayList<>();
51 derivedParams.add(ipv4Params);
52 derivedParams.add(ipv6Params);
55 return Collections.singletonList(params);