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
9 package org.opendaylight.groupbasedpolicy.neutron.ovsdb;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.HashMap;
14 import java.util.List;
16 import java.util.Map.Entry;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeBase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsBuilder;
24 public abstract class AbstractTunnelType {
25 protected static final String REMOTE_IP_KEY = "remote_ip";
26 protected static final String REMOTE_IP_VALUE = "flow";
27 protected static final String VNID_KEY = "key";
28 protected static final String VNID_VALUE = "flow";
30 protected List<Options> createOptionsList(Map<String, String> optionsMap) {
31 List<Options> options = new ArrayList<Options>();
32 OptionsBuilder ob = new OptionsBuilder();
33 for (Entry<String, String> entry: optionsMap.entrySet()) {
34 ob.setOption(entry.getKey());
35 ob.setValue(entry.getValue());
36 options.add(ob.build());
38 return Collections.unmodifiableList(options);
41 protected boolean hasTunnelOptions(OvsdbTerminationPointAugmentation tpAugmentation,
42 Map<String, String> optionsMap) {
44 Map<String, String> foundOpts = new HashMap<String, String>();
45 List<Options> options = tpAugmentation.getOptions();
46 if (options != null) {
47 for (Options opt: options) {
48 // skip invalid options
49 if (opt.getOption() == null
50 || opt.getValue() == null) continue;
52 if (optionsMap.containsKey(opt.getOption())
53 && optionsMap.get(opt.getOption())
54 .equals(opt.getValue())) {
55 foundOpts.put(opt.getOption(), opt.getValue());
58 if ((foundOpts.size() == optionsMap.size())
59 && (options.size() == foundOpts.size())) {
67 * Return the {@link List<Options>} valid for this tunnel type
69 * @return {@link List<Options>} for the tunnel, null if not supported
71 public abstract List<Options> getOptions();
74 * Check if a TerminationPoint is a tunnel port that meets
77 * @param tpAugmentation
78 * @return String of the tunnel port name (null if not found)
80 public abstract boolean isValidTunnelPort(OvsdbTerminationPointAugmentation tpAugmentation);
83 * Return the type of tunnel.
85 * @return type of tunnel
87 public abstract Class<? extends TunnelTypeBase> getTunnelType();
90 * Some {@link AbstractTunnelType} objects have a UDP port property.
91 * This getter method applies to those ports.
93 * @return {@link PortNumber} if the {@link AbstractTunnelType} supports it, null otherwise
95 public abstract PortNumber getPortNumber();
98 * Get the prefix used to create the tunnel name for any tunnels of this type
100 * @return The tunnel prefix
102 public abstract String getTunnelPrefix();