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 {
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, 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 || opt.getValue() == null)
53 if (optionsMap.containsKey(opt.getOption()) && optionsMap.get(opt.getOption()).equals(opt.getValue())) {
54 foundOpts.put(opt.getOption(), opt.getValue());
57 if ((foundOpts.size() == optionsMap.size()) && (options.size() == foundOpts.size())) {
64 protected String getDestPort(OvsdbTerminationPointAugmentation tpAugmentation) {
65 List<Options> options = tpAugmentation.getOptions();
66 if (options == null) {
69 for (Options opt : options) {
70 if (DESTPORT_KEY.equals(opt.getOption())) {
71 return opt.getValue();
78 * Return the list of {@link Options} valid for this tunnel type
80 * @return list of {@link Options} for the tunnel, null if not supported
82 public abstract List<Options> getOptions();
85 * Check if a TerminationPoint is a tunnel port that meets
88 * @param tpAugmentation the {@link OvsdbTerminationPointAugmentation}
89 * @return String of the tunnel port name (null if not found)
91 public abstract boolean isValidTunnelPort(OvsdbTerminationPointAugmentation tpAugmentation);
94 * Return the type of tunnel.
96 * @return type of tunnel
98 public abstract Class<? extends TunnelTypeBase> getTunnelType();
101 * Some {@link AbstractTunnelType} objects have a UDP port property.
102 * This getter method applies to those ports.
104 * @return {@link PortNumber} if the {@link AbstractTunnelType} supports it, null otherwise
106 public abstract PortNumber getPortNumber();
109 * Get the prefix used to create the tunnel name for any tunnels of this type
111 * @return The tunnel prefix
113 public abstract String getTunnelPrefix();