Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-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.sdxl2; |
| 18 | |
| 19 | |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Reference; |
| 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 23 | import org.apache.felix.scr.annotations.Service; |
| 24 | import org.apache.felix.scr.annotations.Activate; |
| 25 | import org.apache.felix.scr.annotations.Deactivate; |
| 26 | import org.onosproject.core.ApplicationId; |
| 27 | import org.onosproject.core.CoreService; |
pierventre | 1483e64 | 2016-06-08 18:52:29 +0200 | [diff] [blame^] | 28 | import org.onosproject.net.ConnectPoint; |
| 29 | import org.onosproject.net.edge.EdgePortService; |
| 30 | import org.onosproject.net.intent.IntentService; |
| 31 | import org.onosproject.net.intent.Key; |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 32 | import org.osgi.service.component.ComponentContext; |
| 33 | import org.slf4j.Logger; |
| 34 | import org.slf4j.LoggerFactory; |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 35 | |
| 36 | import java.util.Collections; |
| 37 | import java.util.Optional; |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 38 | import java.util.Set; |
| 39 | |
| 40 | import static com.google.common.base.Preconditions.checkNotNull; |
| 41 | import static com.google.common.base.Preconditions.checkState; |
| 42 | |
| 43 | /** |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 44 | * Implementation of the SdxL2Service. |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 45 | */ |
| 46 | @Component(immediate = true) |
| 47 | @Service |
| 48 | public class SdxL2Manager implements SdxL2Service { |
| 49 | |
| 50 | private static final String SDXL2_APP = "org.onosproject.sdxl2"; |
| 51 | private static Logger log = LoggerFactory.getLogger(SdxL2Manager.class); |
| 52 | |
| 53 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 54 | protected SdxL2Store sdxL2Store; |
| 55 | |
| 56 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 57 | protected CoreService coreService; |
| 58 | |
pierventre | 1483e64 | 2016-06-08 18:52:29 +0200 | [diff] [blame^] | 59 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 60 | protected IntentService intentService; |
| 61 | |
| 62 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 63 | protected EdgePortService edgePortService; |
| 64 | |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 65 | protected ApplicationId appId; |
| 66 | |
pierventre | 1483e64 | 2016-06-08 18:52:29 +0200 | [diff] [blame^] | 67 | protected SdxL2MonitoringService monitoringManager; |
| 68 | |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 69 | @Activate |
| 70 | protected void activate(ComponentContext context) { |
| 71 | appId = coreService.registerApplication(SDXL2_APP); |
pierventre | 1483e64 | 2016-06-08 18:52:29 +0200 | [diff] [blame^] | 72 | monitoringManager = new SdxL2MonitoringManager(appId, intentService, edgePortService); |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 73 | log.info("Started"); |
| 74 | } |
| 75 | |
| 76 | @Deactivate |
| 77 | protected void deactivate() { |
pierventre | 1483e64 | 2016-06-08 18:52:29 +0200 | [diff] [blame^] | 78 | this.cleanSdxL2(); |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 79 | log.info("Stopped"); |
| 80 | } |
| 81 | |
| 82 | /** |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 83 | * Creates a named SDX-L2. |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 84 | * |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 85 | * @param sdxl2 SDX-L2 name |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 86 | */ |
| 87 | @Override |
| 88 | public void createSdxL2(String sdxl2) { |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 89 | |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 90 | checkNotNull(sdxl2, "sdxl2 name cannot be null"); |
| 91 | checkState(!sdxl2.contains(","), "sdxl2 names cannot contain commas"); |
| 92 | checkState(!sdxl2.contains("|"), "sdxl2 names cannot contain pipe"); |
| 93 | checkState(!sdxl2.contains("-"), "sdxl2 names cannot contain dash"); |
| 94 | checkState(!sdxl2.contains(":"), "sdxl2 names cannot contain colon"); |
| 95 | |
| 96 | try { |
| 97 | this.sdxL2Store.putSdxL2(sdxl2); |
| 98 | } catch (SdxL2Exception e) { |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 99 | log.info(e.getMessage()); |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | } |
| 103 | |
| 104 | /** |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 105 | * Deletes a named SDX-L2. |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 106 | * |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 107 | * @param sdxl2 SDX-L2 name |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 108 | */ |
| 109 | @Override |
| 110 | public void deleteSdxL2(String sdxl2) { |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 111 | |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 112 | checkNotNull(sdxl2, "sdxl2 name cannot be null"); |
| 113 | |
| 114 | try { |
| 115 | this.sdxL2Store.removeSdxL2(sdxl2); |
| 116 | } catch (SdxL2Exception e) { |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 117 | log.info(e.getMessage()); |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | } |
| 121 | |
| 122 | /** |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 123 | * Returns a set of SDX-L2 names. |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 124 | * |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 125 | * @return a set of SDX-L2 names |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 126 | */ |
| 127 | @Override |
| 128 | public Set<String> getSdxL2s() { |
| 129 | return this.sdxL2Store.getSdxL2s(); |
| 130 | } |
| 131 | |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame] | 132 | /** |
| 133 | * Adds an SDX-L2 connection point to an SDX-L2. |
| 134 | * |
| 135 | * @param sdxl2 SDX-L2 name |
| 136 | * @param sdxl2cp SDX-L2 connection point object |
| 137 | */ |
| 138 | @Override |
| 139 | public void addSdxL2ConnectionPoint(String sdxl2, SdxL2ConnectionPoint sdxl2cp) { |
| 140 | |
| 141 | checkNotNull(sdxl2, "sdxl2 name cannot be null"); |
| 142 | checkNotNull(sdxl2cp, "SdxL2ConnectionPoint cannot be null"); |
| 143 | |
| 144 | try { |
| 145 | this.sdxL2Store.addSdxL2ConnectionPoint(sdxl2, sdxl2cp); |
| 146 | } catch (SdxL2Exception e) { |
| 147 | log.info(e.getMessage()); |
| 148 | } |
| 149 | |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Returns all the SDX-L2 connection points names in a SDX-L2 or all the SDX-L2 connection points names. |
| 154 | * |
| 155 | * @param sdxl2 SDX-L2 name |
| 156 | * @return a set of SDX-L2 connection points names |
| 157 | */ |
| 158 | @Override |
| 159 | public Set<String> getSdxL2ConnectionPoints(Optional<String> sdxl2) { |
| 160 | |
| 161 | try { |
| 162 | return this.sdxL2Store.getSdxL2ConnectionPoints(sdxl2); |
| 163 | } catch (SdxL2Exception e) { |
| 164 | log.info(e.getMessage()); |
| 165 | } |
| 166 | |
| 167 | return Collections.emptySet(); |
| 168 | |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Removes an SDX-L2 connection point from an SDX-L2. |
| 173 | * |
| 174 | * @param sdxl2cp SDX-L2 connection point name |
| 175 | */ |
| 176 | @Override |
| 177 | public void removeSdxL2ConnectionPoint(String sdxl2cp) { |
| 178 | |
| 179 | checkNotNull(sdxl2cp, "SdxL2ConnectionPoint name cannot be null"); |
| 180 | |
| 181 | try { |
| 182 | this.sdxL2Store.removeSdxL2ConnectionPoint(sdxl2cp); |
| 183 | } catch (SdxL2Exception e) { |
| 184 | log.info(e.getMessage()); |
| 185 | } |
| 186 | |
| 187 | } |
| 188 | |
pierventre | 1483e64 | 2016-06-08 18:52:29 +0200 | [diff] [blame^] | 189 | /** |
| 190 | * Returns an SDX-L2 connection point in a SDX-L2. |
| 191 | * |
| 192 | * @param sdxl2cp SDX-L2 connection point name |
| 193 | * @return the relative SdxL2ConnectionPoint object |
| 194 | */ |
| 195 | @Override |
| 196 | public SdxL2ConnectionPoint getSdxL2ConnectionPoint(String sdxl2cp) { |
| 197 | checkNotNull(sdxl2cp, "SdxL2ConnectionPoint name cannot be null"); |
| 198 | try { |
| 199 | return this.sdxL2Store.getSdxL2ConnectionPoint(sdxl2cp); |
| 200 | } catch (SdxL2Exception e) { |
| 201 | log.info(e.getMessage()); |
| 202 | } |
| 203 | |
| 204 | return null; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Returns the state of the Intent that has been provided as input. |
| 209 | * |
| 210 | * @param intentKey key of the intent; |
| 211 | * @return the last state of the intent; |
| 212 | */ |
| 213 | @Override |
| 214 | public SdxL2State getIntentState(Key intentKey) { |
| 215 | checkNotNull(intentKey, "Intent key cannot be null"); |
| 216 | return this.monitoringManager.getIntentState(intentKey); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Returns the state of the EdgePort that has been provided as input. |
| 221 | * |
| 222 | * @param edgeport the connect point representing the edge port |
| 223 | * @return the last state of the edgeport; |
| 224 | */ |
| 225 | @Override |
| 226 | public SdxL2State getEdgePortState(ConnectPoint edgeport) { |
| 227 | checkNotNull(edgeport, "Edge port cannot be null"); |
| 228 | return this.monitoringManager.getEdgePortState(edgeport); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Cleans the state of the Application. |
| 233 | */ |
| 234 | @Override |
| 235 | public void cleanSdxL2() { |
| 236 | this.monitoringManager.cleanup(); |
| 237 | } |
| 238 | |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 239 | } |