blob: f73fb240cf7a35eba8de41cae3136018d4dd7bba [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;
28import org.osgi.service.component.ComponentContext;
29import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
pierventre3849e562016-05-11 11:47:32 +020031
32import java.util.Collections;
33import java.util.Optional;
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020034import java.util.Set;
35
36import static com.google.common.base.Preconditions.checkNotNull;
37import static com.google.common.base.Preconditions.checkState;
38
39/**
pierventre3849e562016-05-11 11:47:32 +020040 * Implementation of the SdxL2Service.
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020041 */
42@Component(immediate = true)
43@Service
44public class SdxL2Manager implements SdxL2Service {
45
46 private static final String SDXL2_APP = "org.onosproject.sdxl2";
47 private static Logger log = LoggerFactory.getLogger(SdxL2Manager.class);
48
49 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
50 protected SdxL2Store sdxL2Store;
51
52 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
53 protected CoreService coreService;
54
55 protected ApplicationId appId;
56
57 @Activate
58 protected void activate(ComponentContext context) {
59 appId = coreService.registerApplication(SDXL2_APP);
60 log.info("Started");
61 }
62
63 @Deactivate
64 protected void deactivate() {
65 log.info("Stopped");
66 }
67
68 /**
pierventre3849e562016-05-11 11:47:32 +020069 * Creates a named SDX-L2.
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020070 *
pierventre3849e562016-05-11 11:47:32 +020071 * @param sdxl2 SDX-L2 name
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020072 */
73 @Override
74 public void createSdxL2(String sdxl2) {
pierventre3849e562016-05-11 11:47:32 +020075
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020076 checkNotNull(sdxl2, "sdxl2 name cannot be null");
77 checkState(!sdxl2.contains(","), "sdxl2 names cannot contain commas");
78 checkState(!sdxl2.contains("|"), "sdxl2 names cannot contain pipe");
79 checkState(!sdxl2.contains("-"), "sdxl2 names cannot contain dash");
80 checkState(!sdxl2.contains(":"), "sdxl2 names cannot contain colon");
81
82 try {
83 this.sdxL2Store.putSdxL2(sdxl2);
84 } catch (SdxL2Exception e) {
pierventre3849e562016-05-11 11:47:32 +020085 log.info(e.getMessage());
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020086 }
87
88 }
89
90 /**
pierventre3849e562016-05-11 11:47:32 +020091 * Deletes a named SDX-L2.
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020092 *
pierventre3849e562016-05-11 11:47:32 +020093 * @param sdxl2 SDX-L2 name
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020094 */
95 @Override
96 public void deleteSdxL2(String sdxl2) {
pierventre3849e562016-05-11 11:47:32 +020097
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020098 checkNotNull(sdxl2, "sdxl2 name cannot be null");
99
100 try {
101 this.sdxL2Store.removeSdxL2(sdxl2);
102 } catch (SdxL2Exception e) {
pierventre3849e562016-05-11 11:47:32 +0200103 log.info(e.getMessage());
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200104 }
105
106 }
107
108 /**
pierventre3849e562016-05-11 11:47:32 +0200109 * Returns a set of SDX-L2 names.
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200110 *
pierventre3849e562016-05-11 11:47:32 +0200111 * @return a set of SDX-L2 names
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200112 */
113 @Override
114 public Set<String> getSdxL2s() {
115 return this.sdxL2Store.getSdxL2s();
116 }
117
pierventre3849e562016-05-11 11:47:32 +0200118 /**
119 * Adds an SDX-L2 connection point to an SDX-L2.
120 *
121 * @param sdxl2 SDX-L2 name
122 * @param sdxl2cp SDX-L2 connection point object
123 */
124 @Override
125 public void addSdxL2ConnectionPoint(String sdxl2, SdxL2ConnectionPoint sdxl2cp) {
126
127 checkNotNull(sdxl2, "sdxl2 name cannot be null");
128 checkNotNull(sdxl2cp, "SdxL2ConnectionPoint cannot be null");
129
130 try {
131 this.sdxL2Store.addSdxL2ConnectionPoint(sdxl2, sdxl2cp);
132 } catch (SdxL2Exception e) {
133 log.info(e.getMessage());
134 }
135
136 }
137
138 /**
139 * Returns all the SDX-L2 connection points names in a SDX-L2 or all the SDX-L2 connection points names.
140 *
141 * @param sdxl2 SDX-L2 name
142 * @return a set of SDX-L2 connection points names
143 */
144 @Override
145 public Set<String> getSdxL2ConnectionPoints(Optional<String> sdxl2) {
146
147 try {
148 return this.sdxL2Store.getSdxL2ConnectionPoints(sdxl2);
149 } catch (SdxL2Exception e) {
150 log.info(e.getMessage());
151 }
152
153 return Collections.emptySet();
154
155 }
156
157 /**
158 * Removes an SDX-L2 connection point from an SDX-L2.
159 *
160 * @param sdxl2cp SDX-L2 connection point name
161 */
162 @Override
163 public void removeSdxL2ConnectionPoint(String sdxl2cp) {
164
165 checkNotNull(sdxl2cp, "SdxL2ConnectionPoint name cannot be null");
166
167 try {
168 this.sdxL2Store.removeSdxL2ConnectionPoint(sdxl2cp);
169 } catch (SdxL2Exception e) {
170 log.info(e.getMessage());
171 }
172
173 }
174
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200175}