blob: 66ca6cd7f83c34c63e68c9308cf26955dc8dac3a [file] [log] [blame]
Yuta HIGUCHI48f4cb72018-03-29 20:30:56 -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 */
Yuta HIGUCHId0f8d892018-04-09 12:14:00 -070016package org.onosproject.odtn.utils.openconfig;
Yuta HIGUCHI48f4cb72018-03-29 20:30:56 -070017
18import static org.onosproject.odtn.utils.YangToolUtil.toDataNode;
19
20import java.util.List;
21
22import org.onosproject.yang.gen.v1.openconfigplatform.rev20161222.openconfigplatform.platformcomponenttop.DefaultComponents;
23import org.onosproject.yang.gen.v1.openconfigplatform.rev20161222.openconfigplatform.platformcomponenttop.components.Component;
24import org.onosproject.yang.gen.v1.openconfigplatformtransceiver.rev20170708.openconfigplatformtransceiver.components.component.DefaultAugmentedOcPlatformComponent;
25import org.onosproject.yang.gen.v1.openconfigplatformtransceiver.rev20170708.openconfigplatformtransceiver.porttransceivertop.DefaultTransceiver;
26import org.onosproject.yang.gen.v1.openconfigplatformtransceiver.rev20170708.openconfigplatformtransceiver.porttransceivertop.transceiver.Config;
27import org.onosproject.yang.gen.v1.openconfigplatformtransceiver.rev20170708.openconfigplatformtransceiver.porttransceivertop.transceiver.DefaultConfig;
28import org.onosproject.yang.gen.v1.openconfigtransporttypes.rev20170816.openconfigtransporttypes.Eth100GbaseLr4;
29import org.onosproject.yang.gen.v1.openconfigtransporttypes.rev20170816.openconfigtransporttypes.Qsfp28;
30import org.onosproject.yang.model.DataNode;
31
32import com.google.common.annotations.Beta;
33import com.google.common.collect.ImmutableList;
34
35/**
36 * Utility methods dealing with OpenConfig transceiver.
37 * <p>
38 * Split into classes for the purpose of avoiding "Config" class collisions.
39 */
40@Beta
41public abstract class Transceiver {
42
43 public static List<DataNode> enable(String componentName, boolean enable) {
44
45 DefaultComponents components = new DefaultComponents();
46
47 Component component = PlainPlatform.componentWithName(componentName);
48 components.addToComponent(component);
49
50 // augmented 'component' shim
51 DefaultAugmentedOcPlatformComponent tcomponent = new DefaultAugmentedOcPlatformComponent();
52
53 DefaultTransceiver transceiver = new DefaultTransceiver();
54
55 Config configt = new DefaultConfig();
56 configt.enabled(enable); // phase 1.0 flag
57 transceiver.config(configt);
58 tcomponent.transceiver(transceiver);
59 component.addAugmentation(tcomponent);
60
61 return ImmutableList.of(toDataNode(components));
62 }
63
64 public static List<DataNode> preconf(String componentName) {
65 DefaultComponents components = new DefaultComponents();
66
67 Component component = PlainPlatform.componentWithName(componentName);
68 components.addToComponent(component);
69
70 // augmented 'component' shim
71 DefaultAugmentedOcPlatformComponent tcomponent = new DefaultAugmentedOcPlatformComponent();
72
73 DefaultTransceiver transceiver = new DefaultTransceiver();
74
75 Config configt = new DefaultConfig();
76 // TODO make these configurable
77 configt.formFactorPreconf(Qsfp28.class);
78 configt.ethernetPmdPreconf(Eth100GbaseLr4.class);
79 transceiver.config(configt);
80 tcomponent.transceiver(transceiver);
81 component.addAugmentation(tcomponent);
82
83 return ImmutableList.of(toDataNode(components));
84 }
85
86}