blob: c06442671916f74f77a7d83e17c4ee089ee4c14b [file] [log] [blame]
10068695e340ec92019-10-11 07:03:00 +00001/*
2 * Copyright 2019-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 */
16package org.onosproject.drivers.zte;
17
18import com.google.common.base.Strings;
19import org.onosproject.net.DeviceId;
20import org.onosproject.net.Port;
21import org.onosproject.net.PortNumber;
22import org.onosproject.net.device.DeviceService;
23import org.onosproject.odtn.behaviour.ConfigurableTransceiver;
24import org.onosproject.odtn.behaviour.PlainTransceiver;
25import org.slf4j.Logger;
26
27import java.util.Collections;
28import java.util.List;
29
30import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_NAME;
31import static org.slf4j.LoggerFactory.getLogger;
32
33public class ZteNetconfDeviceTransceiver
34 extends PlainTransceiver
35 implements ConfigurableTransceiver {
36
37 private final Logger log = getLogger(getClass());
38 private static final String ANOTATION_NAME = "xc:operation";
39
40 @Override
41 public List<CharSequence> enable(PortNumber client, PortNumber line, boolean enable) {
42 DeviceId deviceId = handler().data().deviceId();
43 log.info("Discovering ZTE device {}", deviceId);
44
45 Port port = handler().get(DeviceService.class).getPort(deviceId, client);
46 if (port == null) {
47 log.warn("{} does not exist on {}", client, deviceId);
48 return Collections.emptyList();
49 }
50
51 String component = port.annotations().value(OC_NAME);
52 if (Strings.isNullOrEmpty(component)) {
53 log.warn("{} annotation not found on {}@{}", OC_NAME, client, deviceId);
54 return Collections.emptyList();
55 }
56
57 String componentName = component.replace("PORT", "TRANSCEIVER");
58 return enable(componentName, enable);
59 }
60
61
62}