blob: d59b909cff365a5da79f8e1974398af0a9625577 [file] [log] [blame]
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +02001/*
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
17package org.onosproject.sdxl2;
18
19
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Reference;
22import org.apache.felix.scr.annotations.ReferenceCardinality;
23import org.apache.felix.scr.annotations.Service;
24import org.apache.felix.scr.annotations.Activate;
25import org.apache.felix.scr.annotations.Deactivate;
26import org.onosproject.core.ApplicationId;
27import org.onosproject.core.CoreService;
pierventre1483e642016-06-08 18:52:29 +020028import org.onosproject.net.ConnectPoint;
29import org.onosproject.net.edge.EdgePortService;
30import org.onosproject.net.intent.IntentService;
31import org.onosproject.net.intent.Key;
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020032import org.osgi.service.component.ComponentContext;
33import org.slf4j.Logger;
34import org.slf4j.LoggerFactory;
pierventre3849e562016-05-11 11:47:32 +020035
36import java.util.Collections;
37import java.util.Optional;
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020038import java.util.Set;
39
40import static com.google.common.base.Preconditions.checkNotNull;
41import static com.google.common.base.Preconditions.checkState;
42
43/**
pierventre3849e562016-05-11 11:47:32 +020044 * Implementation of the SdxL2Service.
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020045 */
46@Component(immediate = true)
47@Service
48public 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
pierventre1483e642016-06-08 18:52:29 +020059 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 protected IntentService intentService;
61
62 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 protected EdgePortService edgePortService;
64
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020065 protected ApplicationId appId;
66
pierventre1483e642016-06-08 18:52:29 +020067 protected SdxL2MonitoringService monitoringManager;
68
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020069 @Activate
70 protected void activate(ComponentContext context) {
71 appId = coreService.registerApplication(SDXL2_APP);
pierventre1483e642016-06-08 18:52:29 +020072 monitoringManager = new SdxL2MonitoringManager(appId, intentService, edgePortService);
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020073 log.info("Started");
74 }
75
76 @Deactivate
77 protected void deactivate() {
pierventre1483e642016-06-08 18:52:29 +020078 this.cleanSdxL2();
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020079 log.info("Stopped");
80 }
81
82 /**
pierventre3849e562016-05-11 11:47:32 +020083 * Creates a named SDX-L2.
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020084 *
pierventre3849e562016-05-11 11:47:32 +020085 * @param sdxl2 SDX-L2 name
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020086 */
87 @Override
88 public void createSdxL2(String sdxl2) {
pierventre3849e562016-05-11 11:47:32 +020089
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020090 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) {
pierventre3849e562016-05-11 11:47:32 +020099 log.info(e.getMessage());
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200100 }
101
102 }
103
104 /**
pierventre3849e562016-05-11 11:47:32 +0200105 * Deletes a named SDX-L2.
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200106 *
pierventre3849e562016-05-11 11:47:32 +0200107 * @param sdxl2 SDX-L2 name
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200108 */
109 @Override
110 public void deleteSdxL2(String sdxl2) {
pierventre3849e562016-05-11 11:47:32 +0200111
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200112 checkNotNull(sdxl2, "sdxl2 name cannot be null");
113
114 try {
115 this.sdxL2Store.removeSdxL2(sdxl2);
116 } catch (SdxL2Exception e) {
pierventre3849e562016-05-11 11:47:32 +0200117 log.info(e.getMessage());
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200118 }
119
120 }
121
122 /**
pierventre3849e562016-05-11 11:47:32 +0200123 * Returns a set of SDX-L2 names.
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200124 *
pierventre3849e562016-05-11 11:47:32 +0200125 * @return a set of SDX-L2 names
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200126 */
127 @Override
128 public Set<String> getSdxL2s() {
129 return this.sdxL2Store.getSdxL2s();
130 }
131
pierventre3849e562016-05-11 11:47:32 +0200132 /**
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
pierventre1483e642016-06-08 18:52:29 +0200189 /**
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 Ventre0a023f42016-04-30 11:03:15 +0200239}