blob: 2c08d3603a7e45e47755ac10586adf7d7d5107b7 [file] [log] [blame]
janani bf7060cd2017-03-28 19:06:30 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
janani bf7060cd2017-03-28 19:06:30 +05303 *
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
17package org.onosproject.drivers.huawei;
18
19import org.onlab.osgi.ServiceNotFoundException;
20import org.onosproject.config.DynamicConfigService;
21import org.onosproject.config.FailedException;
22import org.onosproject.l3vpn.netl3vpn.BgpDriverInfo;
23import org.onosproject.l3vpn.netl3vpn.BgpInfo;
janani b9ed76be2017-08-29 19:11:33 +053024import org.onosproject.l3vpn.netl3vpn.L3VpnConfig;
25import org.onosproject.l3vpn.netl3vpn.TunnelInfo;
janani bf7060cd2017-03-28 19:06:30 +053026import org.onosproject.net.driver.AbstractHandlerBehaviour;
janani bf7060cd2017-03-28 19:06:30 +053027import org.onosproject.yang.model.DataNode;
28import org.onosproject.yang.model.ModelObjectData;
29import org.onosproject.yang.model.ResourceId;
janani bf7060cd2017-03-28 19:06:30 +053030import org.onosproject.yang.runtime.YangModelRegistry;
31
janani bf7060cd2017-03-28 19:06:30 +053032import static org.onosproject.drivers.huawei.BgpConstructionUtil.getCreateBgp;
janani bd821b182017-03-30 16:34:49 +053033import static org.onosproject.drivers.huawei.BgpConstructionUtil.getDeleteBgp;
janani bf7060cd2017-03-28 19:06:30 +053034import static org.onosproject.drivers.huawei.DriverUtil.DEVICES;
35import static org.onosproject.drivers.huawei.DriverUtil.NAMESPACE;
36import static org.onosproject.drivers.huawei.DriverUtil.SERVICE_NOT_FOUND;
37import static org.onosproject.drivers.huawei.DriverUtil.SLASH;
38import static org.onosproject.drivers.huawei.InsConstructionUtil.getCreateVpnIns;
janani bd821b182017-03-30 16:34:49 +053039import static org.onosproject.drivers.huawei.InsConstructionUtil.getDeleteVpnIns;
janani bf7060cd2017-03-28 19:06:30 +053040import static org.onosproject.drivers.huawei.IntConstructionUtil.getCreateInt;
janani b9ed76be2017-08-29 19:11:33 +053041import static org.onosproject.drivers.huawei.TnlConstructionUtil.getBindTnl;
42import static org.onosproject.drivers.huawei.TnlConstructionUtil.getCreateTnl;
43import static org.onosproject.drivers.huawei.TnlConstructionUtil.getCreateTnlDev;
44import static org.onosproject.drivers.huawei.TnlConstructionUtil.getCreateTnlPol;
45import static org.onosproject.drivers.huawei.TnlConstructionUtil.getDeleteTnl;
janani bf7060cd2017-03-28 19:06:30 +053046
47/**
48 * Configures l3vpn on Huawei devices.
49 */
janani bd821b182017-03-30 16:34:49 +053050public class HuaweiL3VpnConfig extends AbstractHandlerBehaviour
51 implements L3VpnConfig {
janani bf7060cd2017-03-28 19:06:30 +053052
53 /**
54 * YANG model registry.
55 */
56 protected YangModelRegistry modelRegistry;
57
58 /**
59 * Dynamic config service.
60 */
61 protected DynamicConfigService configService;
62
63 /**
64 * Constructs huawei L3VPN config.
65 */
janani bd821b182017-03-30 16:34:49 +053066 public HuaweiL3VpnConfig() {
janani bf7060cd2017-03-28 19:06:30 +053067 }
68
69 /**
70 * Takes the YANG model registry service and registers the driver YANG.
71 * If service is not available it throws exception.
72 */
73 private void init() {
74 try {
75 modelRegistry = handler().get(YangModelRegistry.class);
76 configService = handler().get(DynamicConfigService.class);
janani bf7060cd2017-03-28 19:06:30 +053077 } catch (ServiceNotFoundException e) {
78 throw new ServiceNotFoundException(SERVICE_NOT_FOUND);
79 }
80 }
81
janani bf7060cd2017-03-28 19:06:30 +053082 @Override
janani b9ed76be2017-08-29 19:11:33 +053083 public ModelObjectData createInstance(ModelObjectData objectData) {
janani bf7060cd2017-03-28 19:06:30 +053084 if (modelRegistry == null) {
85 init();
86 }
janani b9ed76be2017-08-29 19:11:33 +053087 return getCreateVpnIns(objectData, isDevicesPresent());
janani bf7060cd2017-03-28 19:06:30 +053088 }
89
90 @Override
janani b9ed76be2017-08-29 19:11:33 +053091 public ModelObjectData bindInterface(ModelObjectData objectData) {
92 return getCreateInt(objectData);
janani bf7060cd2017-03-28 19:06:30 +053093 }
94
95 @Override
janani b9ed76be2017-08-29 19:11:33 +053096 public ModelObjectData createBgpInfo(BgpInfo bgpInfo,
97 BgpDriverInfo bgpConfig) {
98 return getCreateBgp(bgpInfo, bgpConfig);
janani bf7060cd2017-03-28 19:06:30 +053099 }
100
101 @Override
janani b9ed76be2017-08-29 19:11:33 +0530102 public ModelObjectData createTnlDev(TunnelInfo tnlInfo) {
103 return getCreateTnlDev(tnlInfo);
104 }
105
106 @Override
107 public ModelObjectData createTnlPol(TunnelInfo tnlInfo) {
108 return getCreateTnlPol(tnlInfo);
109 }
110
111 @Override
112 public ModelObjectData createTnl(TunnelInfo tnlInfo) {
113 return getCreateTnl(tnlInfo);
114 }
115
116 @Override
117 public ModelObjectData bindTnl(TunnelInfo tnlInfo) {
118 return getBindTnl(tnlInfo);
119 }
120
121 @Override
122 public ModelObjectData deleteInstance(ModelObjectData objectData) {
123 return getDeleteVpnIns(objectData);
124 }
125
126 @Override
127 public ModelObjectData unbindInterface(ModelObjectData objectData) {
janani bf7060cd2017-03-28 19:06:30 +0530128 //TODO:To be committed.
129 return null;
130 }
131
132 @Override
janani b9ed76be2017-08-29 19:11:33 +0530133 public ModelObjectData deleteTnl(TunnelInfo tnlInfo) {
134 return getDeleteTnl(tnlInfo);
135 }
136
137 @Override
138 public ModelObjectData deleteBgpInfo(BgpInfo bgpInfo,
139 BgpDriverInfo bgpConfig) {
140 return getDeleteBgp(bgpInfo, bgpConfig);
janani bf7060cd2017-03-28 19:06:30 +0530141 }
142
143 /**
144 * Returns true if devices, which is the root node present in store;
145 * false otherwise.
146 *
147 * @return true if devices available; false otherwise
148 */
149 private boolean isDevicesPresent() {
150 ResourceId resId = ResourceId.builder()
151 .addBranchPointSchema(SLASH, null)
152 .addBranchPointSchema(DEVICES, NAMESPACE).build();
153 try {
154 DataNode node = configService.readNode(resId, null);
155 if (node != null) {
156 return true;
157 }
158 } catch (FailedException e) {
159 return false;
160 }
161 return false;
162 }
163}