Yuta HIGUCHI | d0f8d89 | 2018-04-09 12:14:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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.odtn.behaviour; |
| 17 | |
Yuta HIGUCHI | 9ee8664 | 2018-05-15 15:25:00 -0700 | [diff] [blame] | 18 | import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_NAME; |
Yuta HIGUCHI | 9ee8664 | 2018-05-15 15:25:00 -0700 | [diff] [blame] | 19 | import static org.slf4j.LoggerFactory.getLogger; |
Yuta HIGUCHI | d0f8d89 | 2018-04-09 12:14:00 -0700 | [diff] [blame] | 20 | |
Yuta HIGUCHI | 9ee8664 | 2018-05-15 15:25:00 -0700 | [diff] [blame] | 21 | import java.util.Collections; |
Yuta HIGUCHI | d0f8d89 | 2018-04-09 12:14:00 -0700 | [diff] [blame] | 22 | import java.util.List; |
| 23 | |
Yuta HIGUCHI | 9ee8664 | 2018-05-15 15:25:00 -0700 | [diff] [blame] | 24 | import org.onosproject.net.DeviceId; |
| 25 | import org.onosproject.net.Port; |
| 26 | import org.onosproject.net.PortNumber; |
| 27 | import org.onosproject.net.device.DeviceService; |
Yuta HIGUCHI | d0f8d89 | 2018-04-09 12:14:00 -0700 | [diff] [blame] | 28 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
Ai Hamano | bd51cdd | 2018-10-18 11:30:07 +0900 | [diff] [blame] | 29 | import org.onosproject.odtn.behaviour.OdtnTerminalDeviceDriver.Operation; |
| 30 | import org.onosproject.odtn.utils.openconfig.OpenConfigComponentsHandler; |
| 31 | import org.onosproject.odtn.utils.openconfig.OpenConfigComponentHandler; |
| 32 | import org.onosproject.odtn.utils.openconfig.OpenConfigConfigOfComponentHandler; |
| 33 | import org.onosproject.odtn.utils.openconfig.OpenConfigConfigOfTransceiverHandler; |
| 34 | import org.onosproject.odtn.utils.openconfig.OpenConfigTransceiverHandler; |
Yuta HIGUCHI | 9ee8664 | 2018-05-15 15:25:00 -0700 | [diff] [blame] | 35 | import org.slf4j.Logger; |
Yuta HIGUCHI | d0f8d89 | 2018-04-09 12:14:00 -0700 | [diff] [blame] | 36 | |
Yuta HIGUCHI | 9ee8664 | 2018-05-15 15:25:00 -0700 | [diff] [blame] | 37 | import com.google.common.base.Strings; |
Yuta HIGUCHI | d0f8d89 | 2018-04-09 12:14:00 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Plain OpenConfig based implementation. |
| 41 | */ |
| 42 | public class PlainTransceiver extends AbstractHandlerBehaviour |
| 43 | implements ConfigurableTransceiver { |
| 44 | |
Yuta HIGUCHI | 9ee8664 | 2018-05-15 15:25:00 -0700 | [diff] [blame] | 45 | private final Logger log = getLogger(getClass()); |
| 46 | |
Ai Hamano | bd51cdd | 2018-10-18 11:30:07 +0900 | [diff] [blame] | 47 | private static final String ANOTATION_NAME = "xc:operation"; |
| 48 | |
Yuta HIGUCHI | d0f8d89 | 2018-04-09 12:14:00 -0700 | [diff] [blame] | 49 | @Override |
Yuta HIGUCHI | 01c66eb | 2018-05-22 12:12:35 -0700 | [diff] [blame] | 50 | public List<CharSequence> enable(PortNumber client, PortNumber line, boolean enable) { |
Yuta HIGUCHI | 9ee8664 | 2018-05-15 15:25:00 -0700 | [diff] [blame] | 51 | DeviceId did = this.data().deviceId(); |
Yuta HIGUCHI | 01c66eb | 2018-05-22 12:12:35 -0700 | [diff] [blame] | 52 | Port port = handler().get(DeviceService.class).getPort(did, client); |
Yuta HIGUCHI | 9ee8664 | 2018-05-15 15:25:00 -0700 | [diff] [blame] | 53 | if (port == null) { |
Yuta HIGUCHI | 01c66eb | 2018-05-22 12:12:35 -0700 | [diff] [blame] | 54 | log.warn("{} does not exist on {}", client, did); |
Yuta HIGUCHI | 9ee8664 | 2018-05-15 15:25:00 -0700 | [diff] [blame] | 55 | return Collections.emptyList(); |
| 56 | } |
| 57 | String component = port.annotations().value(OC_NAME); |
| 58 | if (Strings.isNullOrEmpty(component)) { |
Yuta HIGUCHI | 01c66eb | 2018-05-22 12:12:35 -0700 | [diff] [blame] | 59 | log.warn("{} annotation not found on {}@{}", OC_NAME, client, did); |
Yuta HIGUCHI | 9ee8664 | 2018-05-15 15:25:00 -0700 | [diff] [blame] | 60 | return Collections.emptyList(); |
| 61 | } |
| 62 | return enable(component, enable); |
| 63 | } |
| 64 | |
| 65 | @Override |
Ai Hamano | bd51cdd | 2018-10-18 11:30:07 +0900 | [diff] [blame] | 66 | public List<CharSequence> enable(String componentName, boolean enable) { |
| 67 | // create <components xmlns="http://openconfig.net/yang/platform" |
| 68 | // xc:operation="merge/delete"> |
| 69 | // </components> |
| 70 | OpenConfigComponentsHandler components = new OpenConfigComponentsHandler(); |
| 71 | if (enable) { |
| 72 | components.addAnnotation(ANOTATION_NAME, Operation.MERGE.value()); |
| 73 | } else { |
| 74 | components.addAnnotation(ANOTATION_NAME, Operation.DELETE.value()); |
| 75 | } |
Yuta HIGUCHI | d0f8d89 | 2018-04-09 12:14:00 -0700 | [diff] [blame] | 76 | |
Ai Hamano | bd51cdd | 2018-10-18 11:30:07 +0900 | [diff] [blame] | 77 | // add <component><name>"componentName"</name></component> |
| 78 | OpenConfigComponentHandler component |
| 79 | = new OpenConfigComponentHandler(componentName, components); |
| 80 | |
| 81 | // add <config><name>"componentName"</name></config> |
| 82 | OpenConfigConfigOfComponentHandler configOfComponent |
| 83 | = new OpenConfigConfigOfComponentHandler(component); |
| 84 | configOfComponent.addName(componentName); |
| 85 | |
| 86 | // add <transceiver xmlns="http://openconfig.net/yang/platform/transceiver"></transceiver> |
| 87 | OpenConfigTransceiverHandler transceiver = new OpenConfigTransceiverHandler(component); |
| 88 | |
| 89 | // add <config><enabled>true/false</enabled></config> |
| 90 | OpenConfigConfigOfTransceiverHandler configOfTransceiver |
| 91 | = new OpenConfigConfigOfTransceiverHandler(transceiver); |
| 92 | configOfTransceiver.addEnabled(enable); |
| 93 | |
| 94 | return components.getListCharSequence(); |
Yuta HIGUCHI | d0f8d89 | 2018-04-09 12:14:00 -0700 | [diff] [blame] | 95 | } |
Yuta HIGUCHI | d0f8d89 | 2018-04-09 12:14:00 -0700 | [diff] [blame] | 96 | } |