janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.l3vpn.netl3vpn; |
| 18 | |
| 19 | import org.onosproject.net.DeviceId; |
| 20 | |
janani b | 36b1d77 | 2017-03-27 15:01:28 +0530 | [diff] [blame] | 21 | import java.util.HashMap; |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 22 | import java.util.Map; |
| 23 | |
| 24 | /** |
| 25 | * Representation of stored VPN instance, which contains the configuration |
| 26 | * such as RD and RT, also the device info and the VPN type. |
| 27 | */ |
| 28 | public class VpnInstance<T extends VpnConfig> { |
| 29 | |
| 30 | /** |
| 31 | * VPN instance name. |
| 32 | */ |
| 33 | private String vpnName; |
| 34 | |
| 35 | /** |
| 36 | * List of devices for the VPN. |
| 37 | */ |
| 38 | private Map<DeviceId, DeviceInfo> devInfo; |
| 39 | |
| 40 | /** |
| 41 | * Type of the VPN. |
| 42 | */ |
| 43 | private VpnType type; |
| 44 | |
| 45 | /** |
| 46 | * VPN config information. |
| 47 | */ |
| 48 | private T vpnConfig; |
| 49 | |
| 50 | /** |
| 51 | * Creates VPN instance with VPN name. |
| 52 | * |
| 53 | * @param v VPN name |
| 54 | */ |
| 55 | public VpnInstance(String v) { |
| 56 | vpnName = v; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns the type of the VPN instance. |
| 61 | * |
| 62 | * @return VPN type |
| 63 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 64 | public VpnType type() { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 65 | return type; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Sets the type of the VPN instance. |
| 70 | * |
| 71 | * @param type VPN type |
| 72 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 73 | public void type(VpnType type) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 74 | this.type = type; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Returns the configuration of VPN instance. |
| 79 | * |
| 80 | * @return VPN config |
| 81 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 82 | public T vpnConfig() { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 83 | return vpnConfig; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Sets the configuration of VPN instance. |
| 88 | * |
| 89 | * @param vpnConfig VPN config |
| 90 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 91 | public void vpnConfig(T vpnConfig) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 92 | this.vpnConfig = vpnConfig; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Returns the device info map. |
| 97 | * |
| 98 | * @return device info map |
| 99 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 100 | public Map<DeviceId, DeviceInfo> devInfo() { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 101 | return devInfo; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Sets the device info map. |
| 106 | * |
| 107 | * @param devInfo device info map |
| 108 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 109 | public void devInfo(Map<DeviceId, DeviceInfo> devInfo) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 110 | this.devInfo = devInfo; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Adds the content to device info map. |
| 115 | * |
| 116 | * @param id device id |
| 117 | * @param info device info |
| 118 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 119 | public void addDevInfo(DeviceId id, DeviceInfo info) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 120 | if (devInfo == null) { |
janani b | 36b1d77 | 2017-03-27 15:01:28 +0530 | [diff] [blame] | 121 | devInfo = new HashMap<>(); |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 122 | } |
| 123 | devInfo.put(id, info); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Returns the VPN instance name. |
| 128 | * |
| 129 | * @return VPN name |
| 130 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 131 | public String vpnName() { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 132 | return vpnName; |
| 133 | } |
| 134 | } |