blob: d9c77e3cc6a5f4acd0b6798b78f1034f56a9d73f [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;
31import java.util.Set;
32
33import static com.google.common.base.Preconditions.checkNotNull;
34import static com.google.common.base.Preconditions.checkState;
35
36/**
37 * Implementation of the Interface SdxL2Service.
38 */
39@Component(immediate = true)
40@Service
41public class SdxL2Manager implements SdxL2Service {
42
43 private static final String SDXL2_APP = "org.onosproject.sdxl2";
44 private static Logger log = LoggerFactory.getLogger(SdxL2Manager.class);
45
46 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
47 protected SdxL2Store sdxL2Store;
48
49 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
50 protected CoreService coreService;
51
52 protected ApplicationId appId;
53
54 @Activate
55 protected void activate(ComponentContext context) {
56 appId = coreService.registerApplication(SDXL2_APP);
57 log.info("Started");
58 }
59
60 @Deactivate
61 protected void deactivate() {
62 log.info("Stopped");
63 }
64
65 /**
66 * Create a named sdxl2.
67 *
68 * @param sdxl2 sdxl2 name
69 */
70 @Override
71 public void createSdxL2(String sdxl2) {
72 checkNotNull(sdxl2, "sdxl2 name cannot be null");
73 checkState(!sdxl2.contains(","), "sdxl2 names cannot contain commas");
74 checkState(!sdxl2.contains("|"), "sdxl2 names cannot contain pipe");
75 checkState(!sdxl2.contains("-"), "sdxl2 names cannot contain dash");
76 checkState(!sdxl2.contains(":"), "sdxl2 names cannot contain colon");
77
78 try {
79 this.sdxL2Store.putSdxL2(sdxl2);
80 } catch (SdxL2Exception e) {
81 e.printStackTrace();
82 }
83
84 }
85
86 /**
87 * Delete a named sdxl2.
88 *
89 * @param sdxl2 sdxl2 name
90 */
91 @Override
92 public void deleteSdxL2(String sdxl2) {
93 checkNotNull(sdxl2, "sdxl2 name cannot be null");
94
95 try {
96 this.sdxL2Store.removeSdxL2(sdxl2);
97 } catch (SdxL2Exception e) {
98 e.printStackTrace();
99 }
100
101 }
102
103 /**
104 * Returns a set of sdxl2 names.
105 *
106 * @return a set of sdxl2 names
107 */
108 @Override
109 public Set<String> getSdxL2s() {
110 return this.sdxL2Store.getSdxL2s();
111 }
112
113}