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.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
21 public abstract class ParamDerivator {
24 * It is possible to derive missing parameters.
28 * Ether-type parameter is missing. Derivation policy might instruct: ipv4 and ipv6 flows need
29 * to be created if ether-type parameter is not present. In this case two derivations of
30 * {@code params} should be returned. One with ipv4 ether-type, the other with ipv6.
32 * @param params parameters inserted by user
33 * @return list of {@code params} updated with derived values
35 public abstract List<Map<String, ParameterValue>> deriveParameter(Map<String, ParameterValue> params);
37 public static final ParamDerivator ETHER_TYPE_DERIVATOR = new ParamDerivator() {
40 public List<Map<String, ParameterValue>> deriveParameter(Map<String, ParameterValue> params) {
42 if (!params.containsKey(EtherTypeClassifier.ETHERTYPE_PARAM)) {
43 Map<String, ParameterValue> ipv4Params = new HashMap<>(params);
44 Map<String, ParameterValue> ipv6Params = new HashMap<>(params);
45 ipv4Params.put(EtherTypeClassifier.ETHERTYPE_PARAM, new ParameterValueBuilder().setIntValue(FlowUtils.IPv4)
47 ipv6Params.put(EtherTypeClassifier.ETHERTYPE_PARAM, new ParameterValueBuilder().setIntValue(FlowUtils.IPv6)
49 List<Map<String, ParameterValue>> derivedParams = new ArrayList<>();
50 derivedParams.add(ipv4Params);
51 derivedParams.add(ipv6Params);
54 return Collections.singletonList(params);