Yuta HIGUCHI | 48f4cb7 | 2018-03-29 20:30:56 -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 | */ |
Yuta HIGUCHI | d0f8d89 | 2018-04-09 12:14:00 -0700 | [diff] [blame] | 16 | package org.onosproject.odtn.utils.openconfig; |
Yuta HIGUCHI | 48f4cb7 | 2018-03-29 20:30:56 -0700 | [diff] [blame] | 17 | |
| 18 | import static org.onosproject.odtn.utils.YangToolUtil.toDataNode; |
| 19 | |
| 20 | import java.util.List; |
| 21 | |
| 22 | import org.onosproject.yang.gen.v1.openconfigplatform.rev20161222.openconfigplatform.platformcomponenttop.DefaultComponents; |
| 23 | import org.onosproject.yang.gen.v1.openconfigplatform.rev20161222.openconfigplatform.platformcomponenttop.components.Component; |
| 24 | import org.onosproject.yang.gen.v1.openconfigplatformtransceiver.rev20170708.openconfigplatformtransceiver.components.component.DefaultAugmentedOcPlatformComponent; |
| 25 | import org.onosproject.yang.gen.v1.openconfigplatformtransceiver.rev20170708.openconfigplatformtransceiver.porttransceivertop.DefaultTransceiver; |
| 26 | import org.onosproject.yang.gen.v1.openconfigplatformtransceiver.rev20170708.openconfigplatformtransceiver.porttransceivertop.transceiver.Config; |
| 27 | import org.onosproject.yang.gen.v1.openconfigplatformtransceiver.rev20170708.openconfigplatformtransceiver.porttransceivertop.transceiver.DefaultConfig; |
| 28 | import org.onosproject.yang.gen.v1.openconfigtransporttypes.rev20170816.openconfigtransporttypes.Eth100GbaseLr4; |
| 29 | import org.onosproject.yang.gen.v1.openconfigtransporttypes.rev20170816.openconfigtransporttypes.Qsfp28; |
| 30 | import org.onosproject.yang.model.DataNode; |
| 31 | |
| 32 | import com.google.common.annotations.Beta; |
| 33 | import 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 |
| 41 | public 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 | } |