10068695 | e340ec9 | 2019-10-11 07:03:00 +0000 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.drivers.zte; |
| 17 | |
| 18 | import com.google.common.base.Strings; |
| 19 | import org.onosproject.net.DeviceId; |
| 20 | import org.onosproject.net.Port; |
| 21 | import org.onosproject.net.PortNumber; |
| 22 | import org.onosproject.net.device.DeviceService; |
| 23 | import org.onosproject.odtn.behaviour.ConfigurableTransceiver; |
| 24 | import org.onosproject.odtn.behaviour.PlainTransceiver; |
| 25 | import org.slf4j.Logger; |
| 26 | |
| 27 | import java.util.Collections; |
| 28 | import java.util.List; |
| 29 | |
| 30 | import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_NAME; |
| 31 | import static org.slf4j.LoggerFactory.getLogger; |
| 32 | |
| 33 | public 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 | } |