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