blob: 8618552ad9bd24f117c1b1c982a44ef2f30b8cbf [file] [log] [blame]
samuelbc087c02015-07-23 14:11:58 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
samuelbc087c02015-07-23 14:11:58 +08003 *
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 */
samuelbc087c02015-07-23 14:11:58 +080016
Andrea Campanella238d96e2016-01-20 11:52:02 -080017package org.onosproject.drivers.ovsdb;
samuelbc087c02015-07-23 14:11:58 +080018
19import org.onlab.packet.IpAddress;
20import org.onosproject.net.DeviceId;
Hyunsun Moonaab8c672015-10-27 19:42:12 -070021import org.onosproject.net.behaviour.BridgeName;
samuelbc087c02015-07-23 14:11:58 +080022import org.onosproject.net.behaviour.TunnelConfig;
23import org.onosproject.net.behaviour.TunnelDescription;
samuelbc087c02015-07-23 14:11:58 +080024import org.onosproject.net.driver.AbstractHandlerBehaviour;
25import org.onosproject.net.driver.DriverHandler;
26import org.onosproject.ovsdb.controller.OvsdbClientService;
27import org.onosproject.ovsdb.controller.OvsdbController;
Hyunsun Moondd14e8e2016-06-09 16:17:32 -070028import org.onosproject.ovsdb.controller.OvsdbInterface;
samuelbc087c02015-07-23 14:11:58 +080029import org.onosproject.ovsdb.controller.OvsdbNodeId;
samuelbc087c02015-07-23 14:11:58 +080030
Andrea Campanella238d96e2016-01-20 11:52:02 -080031import java.util.Collection;
Hyunsun Moondd14e8e2016-06-09 16:17:32 -070032import java.util.Collections;
Andrea Campanella238d96e2016-01-20 11:52:02 -080033
samuelbc087c02015-07-23 14:11:58 +080034/**
35 * OVSDB-based implementation of tunnel config behaviour.
Hyunsun Moondd14e8e2016-06-09 16:17:32 -070036 *
37 * @deprecated version 1.7.0 - Hummingbird; use interface config instead
samuelbc087c02015-07-23 14:11:58 +080038 */
Hyunsun Moondd14e8e2016-06-09 16:17:32 -070039@Deprecated
samuelbc087c02015-07-23 14:11:58 +080040public class OvsdbTunnelConfig extends AbstractHandlerBehaviour
41 implements TunnelConfig {
42
samuelbc087c02015-07-23 14:11:58 +080043 @Override
Hyunsun Moonaab8c672015-10-27 19:42:12 -070044 public boolean createTunnelInterface(BridgeName bridgeName, TunnelDescription tunnel) {
Hyunsun Moonaab8c672015-10-27 19:42:12 -070045 DriverHandler handler = handler();
Hyunsun Moondd14e8e2016-06-09 16:17:32 -070046 OvsdbClientService ovsdbNode = getOvsdbNode(handler);
47
48 OvsdbInterface ovsdbIface = OvsdbInterface.builder(tunnel).build();
49 return ovsdbNode.createInterface(bridgeName.name(), ovsdbIface);
Hyunsun Moonaab8c672015-10-27 19:42:12 -070050 }
51
52 @Override
samuelbc087c02015-07-23 14:11:58 +080053 public void removeTunnel(TunnelDescription tunnel) {
54 DriverHandler handler = handler();
55 OvsdbClientService ovsdbNode = getOvsdbNode(handler);
Hyunsun Moondd14e8e2016-06-09 16:17:32 -070056 ovsdbNode.dropInterface(tunnel.ifaceName());
samuelbc087c02015-07-23 14:11:58 +080057 }
58
59 @Override
60 public void updateTunnel(TunnelDescription tunnel) {
61 // TODO Auto-generated method stub
62
63 }
64
65 @Override
66 public Collection<TunnelDescription> getTunnels() {
Hyunsun Moondd14e8e2016-06-09 16:17:32 -070067 return Collections.emptyList();
samuelbc087c02015-07-23 14:11:58 +080068 }
69
jiangrui866c2f22015-10-28 18:58:34 +080070 // OvsdbNodeId(IP) is used in the adaptor while DeviceId(ovsdb:IP)
samuelbc087c02015-07-23 14:11:58 +080071 // is used in the core. So DeviceId need be changed to OvsdbNodeId.
72 private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) {
jiangrui866c2f22015-10-28 18:58:34 +080073 String[] splits = deviceId.toString().split(":");
74 if (splits == null || splits.length < 1) {
75 return null;
76 }
Hyunsun Moondbab8de2015-10-28 16:45:04 -070077 IpAddress ipAddress = IpAddress.valueOf(splits[1]);
jiangrui866c2f22015-10-28 18:58:34 +080078 return new OvsdbNodeId(ipAddress, 0);
samuelbc087c02015-07-23 14:11:58 +080079 }
80
81 private OvsdbClientService getOvsdbNode(DriverHandler handler) {
82 OvsdbController ovsController = handler.get(OvsdbController.class);
83 DeviceId deviceId = handler.data().deviceId();
84 OvsdbNodeId nodeId = changeDeviceIdToNodeId(deviceId);
85 return ovsController.getOvsdbClient(nodeId);
86 }
87}