blob: 9248dd4984752e0ad053aea85b03d3d9c3cefee3 [file] [log] [blame]
Ai Hamanobd51cdd2018-10-18 11:30:07 +09001/*
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
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.net.driver.AbstractHandlerBehaviour;
24import org.onosproject.odtn.behaviour.OdtnTerminalDeviceDriver.Operation;
25import org.onosproject.odtn.utils.openconfig.OpenConfigAssignmentHandler;
26import org.onosproject.odtn.utils.openconfig.OpenConfigChannelHandler;
27import org.onosproject.odtn.utils.openconfig.OpenConfigConfigOfAssignmentHandler;
28import org.onosproject.odtn.utils.openconfig.OpenConfigConfigOfChannelHandler;
29import org.onosproject.odtn.utils.openconfig.OpenConfigLogicalChannelAssignmentsHandler;
30import org.onosproject.odtn.utils.openconfig.OpenConfigLogicalChannelsHandler;
31import org.onosproject.odtn.utils.openconfig.OpenConfigTerminalDeviceHandler;
hiroki096259b2018-12-07 09:33:24 -080032import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanassignmentconfig.AssignmentTypeEnum;
Ai Hamanobd51cdd2018-10-18 11:30:07 +090033
34import org.slf4j.Logger;
35
36import java.math.BigDecimal;
37import java.util.Collections;
38import java.util.List;
39import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_NAME;
40import static org.slf4j.LoggerFactory.getLogger;
41
42/**
43 * Utility class for NETCONF driver.
44 */
45public class InfineraTransceiver extends AbstractHandlerBehaviour
46 implements ConfigurableTransceiver {
47
48 private final Logger log = getLogger(getClass());
49
50 private static final String ANOTATION_NAME = "xc:operation";
51
52 @Override
53 public List<CharSequence> enable(PortNumber client, PortNumber line, boolean enable) {
54
55 log.debug("enable() infinera route");
56 DeviceId did = this.data().deviceId();
57 Port clientPort = handler().get(DeviceService.class).getPort(did, client);
58 if (clientPort == null) {
59 log.warn("{} does not exist on {}", client, did);
60 return Collections.emptyList();
61 }
62 String clientName = clientPort.annotations().value(OC_NAME);
63 if (Strings.isNullOrEmpty(clientName)) {
64 log.warn("{} annotations not exist on {}@{}", OC_NAME, client, did);
65 return Collections.emptyList();
66 }
67
68 Port linePort = handler().get(DeviceService.class).getPort(did, line);
69 if (linePort == null) {
70 log.warn("{} does not exist on {}", line, did);
71 return Collections.emptyList();
72 }
73 String lineName = linePort.annotations().value(OC_NAME);
74 if (Strings.isNullOrEmpty(lineName)) {
75 log.warn("{} annotations not exist on {}@{}", OC_NAME, line, did);
76 return Collections.emptyList();
77 }
78
79 // create <terminal-device xmlns="http://openconfig.net/yang/terminal-device">
80 // </terminal-device>
81 OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler();
82
83 // add <logical-channels></logical-channels>
84 OpenConfigLogicalChannelsHandler logicalChannels =
85 new OpenConfigLogicalChannelsHandler(terminalDevice);
86
87 // add <channel><index>"clientName"</index></channel>
88 OpenConfigChannelHandler channel =
hiroki096259b2018-12-07 09:33:24 -080089 new OpenConfigChannelHandler(Integer.parseInt(clientName), logicalChannels);
Ai Hamanobd51cdd2018-10-18 11:30:07 +090090
91 // add <config><index>"clientName"</index></config>
92 OpenConfigConfigOfChannelHandler configOfChannel =
93 new OpenConfigConfigOfChannelHandler(channel);
hiroki096259b2018-12-07 09:33:24 -080094 configOfChannel.addIndex(Integer.parseInt(clientName));
Ai Hamanobd51cdd2018-10-18 11:30:07 +090095
96 // add <logical-channel-assignments xc:operation="merge/delete">
97 OpenConfigLogicalChannelAssignmentsHandler logicalChannelAssignments =
98 new OpenConfigLogicalChannelAssignmentsHandler(channel);
99 if (enable) {
100 logicalChannelAssignments.addAnnotation(ANOTATION_NAME, Operation.MERGE.value());
101 } else {
102 logicalChannelAssignments.addAnnotation(ANOTATION_NAME, Operation.DELETE.value());
103 }
104
105 // add <assignment><index>"clientName"</index></assignment>
106 OpenConfigAssignmentHandler assignment =
hiroki096259b2018-12-07 09:33:24 -0800107 new OpenConfigAssignmentHandler(Integer.parseInt(clientName), logicalChannelAssignments);
Ai Hamanobd51cdd2018-10-18 11:30:07 +0900108
109 // add <config><assignment-type>LOGICAL_CHANNEL</assignment-type>
110 // <logical-channel>"lineName"</logical-channel>
111 // <allocation>100</allocation>
112 // </config>
113 OpenConfigConfigOfAssignmentHandler configOfAssignment =
114 new OpenConfigConfigOfAssignmentHandler(assignment);
115 configOfAssignment.addAssignmentType(AssignmentTypeEnum.LOGICAL_CHANNEL);
116 configOfAssignment.addLogicalChannel(lineName);
117 configOfAssignment.addAllocation(BigDecimal.valueOf(100));
118
119 return terminalDevice.getListCharSequence();
120 }
121}