/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.groupbasedpolicy.renderer.iovisor.sf; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder; public abstract class ParamDerivator { /** * TODO: These are buried somewhere in MDSAL MODEL but NFI how to tease them out. Seems * ridiculous we have to pull these sort of things * in from OFP of LLDP or some such. Quicker to just define them here and rant about it in a * comment. */ /** * IPv4 ethertype */ public static final Long IPv4 = Long.valueOf(0x0800); /** * IPv6 ethertype */ public static final Long IPv6 = Long.valueOf(0x86DD); /** * It is possible to derive missing parameters. * <p> * Examle: * <p> * Ether-type parameter is missing. Derivation policy might instruct: ipv4 and ipv6 flows need * to be created if ether-type parameter is not present. In this case two derivations of * {@code params} should be returned. One with ipv4 ether-type, the other with ipv6. * * @param params parameters inserted by user * @return list of {@code params} updated with derived values */ public abstract List<Map<String, ParameterValue>> deriveParameter(Map<String, ParameterValue> params); public static final ParamDerivator ETHER_TYPE_DERIVATOR = new ParamDerivator() { @Override public List<Map<String, ParameterValue>> deriveParameter(Map<String, ParameterValue> params) { if (!params.containsKey(EtherTypeClassifierDefinition.ETHERTYPE_PARAM)) { Map<String, ParameterValue> ipv4Params = new HashMap<>(params); Map<String, ParameterValue> ipv6Params = new HashMap<>(params); ipv4Params.put(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, new ParameterValueBuilder().setIntValue(IPv4).build()); ipv6Params.put(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, new ParameterValueBuilder().setIntValue(IPv6).build()); List<Map<String, ParameterValue>> derivedParams = new ArrayList<>(); derivedParams.add(ipv4Params); derivedParams.add(ipv6Params); return derivedParams; } return Collections.singletonList(params); } }; }