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; |
| 28 | import org.osgi.service.component.ComponentContext; |
| 29 | import org.slf4j.Logger; |
| 30 | import org.slf4j.LoggerFactory; |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 31 | |
| 32 | import java.util.Collections; |
| 33 | import java.util.Optional; |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 34 | import java.util.Set; |
| 35 | |
| 36 | import static com.google.common.base.Preconditions.checkNotNull; |
| 37 | import static com.google.common.base.Preconditions.checkState; |
| 38 | |
| 39 | /** |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 40 | * Implementation of the SdxL2Service. |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 41 | */ |
| 42 | @Component(immediate = true) |
| 43 | @Service |
| 44 | public 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 | /** |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 69 | * Creates a named SDX-L2. |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 70 | * |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 71 | * @param sdxl2 SDX-L2 name |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 72 | */ |
| 73 | @Override |
| 74 | public void createSdxL2(String sdxl2) { |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 75 | |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 76 | 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) { |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 85 | log.info(e.getMessage()); |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | } |
| 89 | |
| 90 | /** |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 91 | * Deletes a named SDX-L2. |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 92 | * |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 93 | * @param sdxl2 SDX-L2 name |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 94 | */ |
| 95 | @Override |
| 96 | public void deleteSdxL2(String sdxl2) { |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 97 | |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 98 | checkNotNull(sdxl2, "sdxl2 name cannot be null"); |
| 99 | |
| 100 | try { |
| 101 | this.sdxL2Store.removeSdxL2(sdxl2); |
| 102 | } catch (SdxL2Exception e) { |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 103 | log.info(e.getMessage()); |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | } |
| 107 | |
| 108 | /** |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 109 | * Returns a set of SDX-L2 names. |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 110 | * |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 111 | * @return a set of SDX-L2 names |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 112 | */ |
| 113 | @Override |
| 114 | public Set<String> getSdxL2s() { |
| 115 | return this.sdxL2Store.getSdxL2s(); |
| 116 | } |
| 117 | |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 118 | /** |
| 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 Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 175 | } |