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.rev130715.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 {
26 protected static final String DESTPORT_KEY = "dst_port";
27 protected static final String REMOTE_IP_KEY = "remote_ip";
28 protected static final String REMOTE_IP_VALUE = "flow";
29 protected static final String VNID_KEY = "key";
30 protected static final String VNID_VALUE = "flow";
32 protected List<Options> createOptionsList(Map<String, String> optionsMap) {
33 List<Options> options = new ArrayList<Options>();
34 OptionsBuilder ob = new OptionsBuilder();
35 for (Entry<String, String> entry : optionsMap.entrySet()) {
36 ob.setOption(entry.getKey());
37 ob.setValue(entry.getValue());
38 options.add(ob.build());
40 return Collections.unmodifiableList(options);
43 protected boolean hasTunnelOptions(OvsdbTerminationPointAugmentation tpAugmentation,
44 Map<String, String> optionsMap) {
46 Map<String, String> foundOpts = new HashMap<String, String>();
47 List<Options> options = tpAugmentation.getOptions();
48 if (options != null) {
49 for (Options opt : options) {
50 // skip invalid options
51 if (opt.getOption() == null || opt.getValue() == null) {
54 if (optionsMap.containsKey(opt.getOption()) && optionsMap.get(opt.getOption()).equals(opt.getValue())) {
55 foundOpts.put(opt.getOption(), opt.getValue());
58 if ((foundOpts.size() == optionsMap.size()) && (options.size() == foundOpts.size())) {
65 protected String getDestPort(OvsdbTerminationPointAugmentation tpAugmentation) {
66 List<Options> options = tpAugmentation.getOptions();
67 if (options == null) {
70 for (Options opt : options) {
71 if (DESTPORT_KEY.equals(opt.getOption())) {
72 return opt.getValue();
79 * Return the list of {@link Options} valid for this tunnel type.
81 * @return list of {@link Options} for the tunnel, null if not supported
83 public abstract List<Options> getOptions();
86 * Check if a TerminationPoint is a tunnel port that meets.
89 * @param tpAugmentation the {@link OvsdbTerminationPointAugmentation}
90 * @return String of the tunnel port name (null if not found)
92 public abstract boolean isValidTunnelPort(OvsdbTerminationPointAugmentation tpAugmentation);
95 * Return the type of tunnel.
97 * @return type of tunnel
99 public abstract Class<? extends TunnelTypeBase> getTunnelType();
102 * Some {@link AbstractTunnelType} objects have a UDP port property.
103 * This getter method applies to those ports.
105 * @return {@link PortNumber} if the {@link AbstractTunnelType} supports it, null otherwise
107 public abstract PortNumber getPortNumber();
110 * Get the prefix used to create the tunnel name for any tunnels of this type.
112 * @return The tunnel prefix
114 public abstract String getTunnelPrefix();