Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 1 | package org.onosproject.segmentrouting.config; |
| 2 | |
| 3 | import java.util.List; |
| 4 | |
| 5 | import org.onosproject.net.DeviceId; |
| 6 | import org.onosproject.net.Link; |
| 7 | import org.onosproject.segmentrouting.config.NetworkConfig.LinkConfig; |
| 8 | import org.onosproject.segmentrouting.config.NetworkConfig.SwitchConfig; |
| 9 | |
| 10 | /** |
| 11 | * Exposes methods to retrieve network configuration. |
| 12 | * |
| 13 | * TODO: currently only startup-configuration is exposed and such configuration |
| 14 | * cannot be changed at runtime. Need to add runtime support for changes to |
| 15 | * configuration (via REST/CLI) in future releases. |
| 16 | * |
| 17 | * TODO: return immutable objects or defensive copies of network config so that |
| 18 | * users of this API do not inadvertently or maliciously change network config. |
| 19 | */ |
| 20 | public interface NetworkConfigService { |
| 21 | |
| 22 | /** |
| 23 | * Suggests the action to be taken by the caller given the configuration |
| 24 | * associated with the queried network-object (eg. switch, link etc.). |
| 25 | */ |
Sho SHIMIZU | 652a3e7 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 26 | enum NetworkConfigState { |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Associated network object has been configured to not be allowed in |
| 29 | * the network. |
| 30 | */ |
| 31 | DENY, |
| 32 | |
| 33 | /** |
| 34 | * Associated network object has been configured to be allowed in the |
| 35 | * network. |
| 36 | */ |
| 37 | ACCEPT, |
| 38 | |
| 39 | /** |
| 40 | * Associated network object has been configured to be allowed in the |
| 41 | * network. In addition, there are configured parameters that should be |
| 42 | * added to the object. |
| 43 | */ |
| 44 | ACCEPT_ADD, |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns the configuration outcome (accept, deny etc.), and any configured |
| 49 | * parameters to the caller, in response to a query for the configuration |
| 50 | * associated with a switch. |
| 51 | */ |
Sho SHIMIZU | 652a3e7 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 52 | class SwitchConfigStatus { |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 53 | private NetworkConfigState configState; |
| 54 | private SwitchConfig switchConfig; |
| 55 | private String msg; |
| 56 | |
| 57 | SwitchConfigStatus(NetworkConfigState configState, |
| 58 | SwitchConfig switchConfig, String msg) { |
| 59 | this.configState = configState; |
| 60 | this.switchConfig = switchConfig; |
| 61 | this.msg = msg; |
| 62 | } |
| 63 | |
| 64 | SwitchConfigStatus(NetworkConfigState configState, |
| 65 | SwitchConfig switchConfig) { |
| 66 | this.configState = configState; |
| 67 | this.switchConfig = switchConfig; |
| 68 | this.msg = ""; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns the configuration state for the switch. |
| 73 | * |
| 74 | * @return non-null NetworkConfigState |
| 75 | */ |
| 76 | public NetworkConfigState getConfigState() { |
| 77 | return configState; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns the switch configuration, which may be null if no |
| 82 | * configuration exists, or if the configuration state disallows the |
| 83 | * switch. |
| 84 | * |
| 85 | * @return SwitchConfig, the switch configuration, or null |
| 86 | */ |
| 87 | public SwitchConfig getSwitchConfig() { |
| 88 | return switchConfig; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * User readable string typically used to specify the reason why a |
| 93 | * switch is being disallowed. |
| 94 | * |
| 95 | * @return A non-null but possibly empty String |
| 96 | */ |
| 97 | public String getMsg() { |
| 98 | return msg; |
| 99 | } |
| 100 | |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Reserved for future use. |
| 105 | * |
| 106 | * Returns the configuration outcome (accept, deny etc.), and any configured |
| 107 | * parameters to the caller, in response to a query for the configuration |
| 108 | * associated with a link. |
| 109 | */ |
Sho SHIMIZU | 652a3e7 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 110 | class LinkConfigStatus { |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 111 | private NetworkConfigState configState; |
| 112 | private LinkConfig linkConfig; |
| 113 | private String msg; |
| 114 | |
| 115 | LinkConfigStatus(NetworkConfigState configState, |
| 116 | LinkConfig linkConfig, String msg) { |
| 117 | this.configState = configState; |
| 118 | this.linkConfig = linkConfig; |
| 119 | this.msg = msg; |
| 120 | } |
| 121 | |
| 122 | LinkConfigStatus(NetworkConfigState configState, |
| 123 | LinkConfig linkConfig) { |
| 124 | this.configState = configState; |
| 125 | this.linkConfig = linkConfig; |
| 126 | this.msg = ""; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Returns the configuration state for the link. |
| 131 | * |
| 132 | * @return non-null NetworkConfigState |
| 133 | */ |
| 134 | public NetworkConfigState getConfigState() { |
| 135 | return configState; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Returns the link configuration, which may be null if no configuration |
| 140 | * exists, or if the configuration state disallows the link. |
| 141 | * |
| 142 | * @return SwitchConfig, the switch configuration, or null |
| 143 | */ |
| 144 | public LinkConfig getLinkConfig() { |
| 145 | return linkConfig; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * User readable string typically used to specify the reason why a link |
| 150 | * is being disallowed. |
| 151 | * |
| 152 | * @return msg A non-null but possibly empty String |
| 153 | */ |
| 154 | public String getMsg() { |
| 155 | return msg; |
| 156 | } |
| 157 | |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Checks the switch configuration (if any) associated with the 'dpid'. |
| 162 | * Determines if the switch should be allowed or denied according to |
| 163 | * configuration rules. |
| 164 | * |
| 165 | * The method always returns a non-null SwitchConfigStatus. The enclosed |
| 166 | * ConfigState contains the result of the check. The enclosed SwitchConfig |
| 167 | * may or may not be null, depending on the outcome of the check. |
| 168 | * |
| 169 | * @param dpid device id of the switch to be queried |
| 170 | * @return SwitchConfigStatus with outcome of check and associated config. |
| 171 | */ |
Sho SHIMIZU | 652a3e7 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 172 | SwitchConfigStatus checkSwitchConfig(DeviceId dpid); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * Reserved for future use. |
| 176 | * |
| 177 | * Checks the link configuration (if any) associated with the 'link'. |
| 178 | * Determines if the link should be allowed or denied according to |
| 179 | * configuration rules. Note that the 'link' is a unidirectional link which |
| 180 | * checked against configuration that is typically defined for a |
| 181 | * bidirectional link. The caller may make a second call if it wishes to |
| 182 | * check the 'reverse' direction. |
| 183 | * |
| 184 | * Also note that the configuration may not specify ports for a given |
| 185 | * bidirectional link. In such cases, the configuration applies to all links |
| 186 | * between the two switches. This method will check the given 'link' against |
| 187 | * such configuration. |
| 188 | |
| 189 | * The method always returns a non-null LinkConfigStatus. The enclosed |
| 190 | * ConfigState contains the result of the check. The enclosed LinkConfig may |
| 191 | * or may not be null, depending on the outcome of the check. |
| 192 | * |
| 193 | * @param linkTuple unidirectional link to be queried |
| 194 | * @return LinkConfigStatus with outcome of check and associated config. |
| 195 | */ |
Sho SHIMIZU | 652a3e7 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 196 | LinkConfigStatus checkLinkConfig(Link linkTuple); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * Retrieves a list of switches that have been configured, and have been |
| 200 | * determined to be 'allowed' in the network, according to configuration |
| 201 | * rules. |
| 202 | * |
| 203 | * Note that it is possible that there are other switches that are allowed |
| 204 | * in the network that have NOT been configured. Such switches will not be a |
| 205 | * part of the returned list. |
| 206 | * |
| 207 | * Also note that it is possible that some switches will not be discovered |
| 208 | * and the only way the controller can know about these switches is via |
| 209 | * configuration. Such switches will be included in this list. It is up to |
| 210 | * the caller to determine which SwitchConfig applies to non-discovered |
| 211 | * switches. |
| 212 | * |
| 213 | * @return a non-null List of SwitchConfig which may be empty |
| 214 | */ |
Sho SHIMIZU | 652a3e7 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 215 | List<SwitchConfig> getConfiguredAllowedSwitches(); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * Reserved for future use. |
| 219 | * |
| 220 | * Retrieves a list of links that have been configured, and have been |
| 221 | * determined to be 'allowed' in the network, according to configuration |
| 222 | * rules. |
| 223 | * |
| 224 | * Note that it is possible that there are other links that are allowed in |
| 225 | * the network that have NOT been configured. Such links will not be a part |
| 226 | * of the returned list. |
| 227 | * |
| 228 | * Also note that it is possible that some links will not be discovered and |
| 229 | * the only way the controller can know about these links is via |
| 230 | * configuration. Such links will be included in this list. It is up to the |
| 231 | * caller to determine which LinkConfig applies to non-discovered links. |
| 232 | * |
| 233 | * In addition, note that the LinkConfig applies to the configured |
| 234 | * bi-directional link, which may or may not have declared ports. The |
| 235 | * associated unidirectional LinkTuple can be retrieved from the |
| 236 | * getLinkTupleList() method in the LinkConfig object. |
| 237 | * |
| 238 | * @return a non-null List of LinkConfig which may be empty |
| 239 | */ |
Sho SHIMIZU | 652a3e7 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 240 | List<LinkConfig> getConfiguredAllowedLinks(); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 241 | |
| 242 | /** |
| 243 | * Retrieves the Dpid associated with a 'name' for a configured switch |
| 244 | * object. This method does not check of the switches are 'allowed' by |
| 245 | * config. |
| 246 | * |
| 247 | * @param name device name |
| 248 | * @return the Dpid corresponding to a given 'name', or null if no |
| 249 | * configured switch was found for the given 'name'. |
| 250 | */ |
Sho SHIMIZU | 652a3e7 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 251 | DeviceId getDpidForName(String name); |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 252 | |
| 253 | } |