blob: a943f7a73ccefb7cb103d210b952c9ad1eb47f75 [file] [log] [blame]
fahadnaeemkhan482951f2017-08-24 16:35:17 -07001/*
2 * Copyright 2016-present Open Networking Foundation
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.drivers.ciena;
18
19import org.onlab.util.Tools;
fahadnaeemkhan482951f2017-08-24 16:35:17 -070020import org.onosproject.net.PortNumber;
21import org.onosproject.net.behaviour.PortAdmin;
fahadnaeemkhan482951f2017-08-24 16:35:17 -070022import org.onosproject.net.driver.AbstractHandlerBehaviour;
fahadnaeemkhan482951f2017-08-24 16:35:17 -070023import org.slf4j.Logger;
24
fahadnaeemkhan482951f2017-08-24 16:35:17 -070025import java.util.concurrent.CompletableFuture;
fahadnaeemkhan482951f2017-08-24 16:35:17 -070026
fahadnaeemkhan482951f2017-08-24 16:35:17 -070027import static org.slf4j.LoggerFactory.getLogger;
28
29
30public class CienaWaveserverPortAdmin extends AbstractHandlerBehaviour
31 implements PortAdmin {
fahadnaeemkhan71827242017-09-21 15:10:07 -070032 private CienaRestDevice restCiena;
fahadnaeemkhan482951f2017-08-24 16:35:17 -070033 private final Logger log = getLogger(getClass());
fahadnaeemkhan482951f2017-08-24 16:35:17 -070034
35 @Override
36 public CompletableFuture<Boolean> disable(PortNumber number) {
fahadnaeemkhan71827242017-09-21 15:10:07 -070037 try {
38 restCiena = new CienaRestDevice(handler());
39 } catch (NullPointerException e) {
40 log.error("unable to create CienaRestDevice, {}", e);
41 return CompletableFuture.completedFuture(false);
fahadnaeemkhan482951f2017-08-24 16:35:17 -070042 }
fahadnaeemkhan71827242017-09-21 15:10:07 -070043 return CompletableFuture.completedFuture(restCiena.disablePort(number));
fahadnaeemkhan482951f2017-08-24 16:35:17 -070044 }
45
46 @Override
47 public CompletableFuture<Boolean> enable(PortNumber number) {
fahadnaeemkhan71827242017-09-21 15:10:07 -070048 try {
49 restCiena = new CienaRestDevice(handler());
50 } catch (NullPointerException e) {
51 log.error("unable to create CienaRestDevice, {}", e);
52 return CompletableFuture.completedFuture(false);
fahadnaeemkhan482951f2017-08-24 16:35:17 -070053 }
fahadnaeemkhan71827242017-09-21 15:10:07 -070054 return CompletableFuture.completedFuture(restCiena.enablePort(number));
fahadnaeemkhan482951f2017-08-24 16:35:17 -070055 }
56
57 @Override
58 public CompletableFuture<Boolean> isEnabled(PortNumber number) {
59 return Tools.exceptionalFuture(
60 new UnsupportedOperationException("isEnabled is not supported"));
61
62 }
63}