blob: 53a7085d6081517160709606d7b22744aabb3af3 [file] [log] [blame]
Yuta HIGUCHId0f8d892018-04-09 12:14:00 -07001/*
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 */
16package org.onosproject.odtn.behaviour;
17
Yuta HIGUCHI9ee86642018-05-15 15:25:00 -070018import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_NAME;
Yuta HIGUCHI9ee86642018-05-15 15:25:00 -070019import static org.slf4j.LoggerFactory.getLogger;
Yuta HIGUCHId0f8d892018-04-09 12:14:00 -070020
Yuta HIGUCHI9ee86642018-05-15 15:25:00 -070021import java.util.Collections;
Yuta HIGUCHId0f8d892018-04-09 12:14:00 -070022import java.util.List;
23
Yuta HIGUCHI9ee86642018-05-15 15:25:00 -070024import org.onosproject.net.DeviceId;
25import org.onosproject.net.Port;
26import org.onosproject.net.PortNumber;
27import org.onosproject.net.device.DeviceService;
Yuta HIGUCHId0f8d892018-04-09 12:14:00 -070028import org.onosproject.net.driver.AbstractHandlerBehaviour;
Ai Hamanobd51cdd2018-10-18 11:30:07 +090029import org.onosproject.odtn.behaviour.OdtnTerminalDeviceDriver.Operation;
30import org.onosproject.odtn.utils.openconfig.OpenConfigComponentsHandler;
31import org.onosproject.odtn.utils.openconfig.OpenConfigComponentHandler;
32import org.onosproject.odtn.utils.openconfig.OpenConfigConfigOfComponentHandler;
33import org.onosproject.odtn.utils.openconfig.OpenConfigConfigOfTransceiverHandler;
34import org.onosproject.odtn.utils.openconfig.OpenConfigTransceiverHandler;
Yuta HIGUCHI9ee86642018-05-15 15:25:00 -070035import org.slf4j.Logger;
Yuta HIGUCHId0f8d892018-04-09 12:14:00 -070036
Yuta HIGUCHI9ee86642018-05-15 15:25:00 -070037import com.google.common.base.Strings;
Yuta HIGUCHId0f8d892018-04-09 12:14:00 -070038
39/**
40 * Plain OpenConfig based implementation.
41 */
42public class PlainTransceiver extends AbstractHandlerBehaviour
43 implements ConfigurableTransceiver {
44
Yuta HIGUCHI9ee86642018-05-15 15:25:00 -070045 private final Logger log = getLogger(getClass());
46
Ai Hamanobd51cdd2018-10-18 11:30:07 +090047 private static final String ANOTATION_NAME = "xc:operation";
48
Yuta HIGUCHId0f8d892018-04-09 12:14:00 -070049 @Override
Yuta HIGUCHI01c66eb2018-05-22 12:12:35 -070050 public List<CharSequence> enable(PortNumber client, PortNumber line, boolean enable) {
Yuta HIGUCHI9ee86642018-05-15 15:25:00 -070051 DeviceId did = this.data().deviceId();
Yuta HIGUCHI01c66eb2018-05-22 12:12:35 -070052 Port port = handler().get(DeviceService.class).getPort(did, client);
Yuta HIGUCHI9ee86642018-05-15 15:25:00 -070053 if (port == null) {
Yuta HIGUCHI01c66eb2018-05-22 12:12:35 -070054 log.warn("{} does not exist on {}", client, did);
Yuta HIGUCHI9ee86642018-05-15 15:25:00 -070055 return Collections.emptyList();
56 }
57 String component = port.annotations().value(OC_NAME);
58 if (Strings.isNullOrEmpty(component)) {
Yuta HIGUCHI01c66eb2018-05-22 12:12:35 -070059 log.warn("{} annotation not found on {}@{}", OC_NAME, client, did);
Yuta HIGUCHI9ee86642018-05-15 15:25:00 -070060 return Collections.emptyList();
61 }
62 return enable(component, enable);
63 }
64
65 @Override
Ai Hamanobd51cdd2018-10-18 11:30:07 +090066 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 HIGUCHId0f8d892018-04-09 12:14:00 -070076
Ai Hamanobd51cdd2018-10-18 11:30:07 +090077 // 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 HIGUCHId0f8d892018-04-09 12:14:00 -070095 }
Yuta HIGUCHId0f8d892018-04-09 12:14:00 -070096}