samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 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 | */ |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 16 | |
Andrea Campanella | 238d96e | 2016-01-20 11:52:02 -0800 | [diff] [blame] | 17 | package org.onosproject.drivers.ovsdb; |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 18 | |
| 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onosproject.net.DeviceId; |
Hyunsun Moon | aab8c67 | 2015-10-27 19:42:12 -0700 | [diff] [blame] | 21 | import org.onosproject.net.behaviour.BridgeName; |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 22 | import org.onosproject.net.behaviour.TunnelConfig; |
| 23 | import org.onosproject.net.behaviour.TunnelDescription; |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 24 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 25 | import org.onosproject.net.driver.DriverHandler; |
| 26 | import org.onosproject.ovsdb.controller.OvsdbClientService; |
| 27 | import org.onosproject.ovsdb.controller.OvsdbController; |
Hyunsun Moon | dd14e8e | 2016-06-09 16:17:32 -0700 | [diff] [blame] | 28 | import org.onosproject.ovsdb.controller.OvsdbInterface; |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 29 | import org.onosproject.ovsdb.controller.OvsdbNodeId; |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 30 | |
Andrea Campanella | 238d96e | 2016-01-20 11:52:02 -0800 | [diff] [blame] | 31 | import java.util.Collection; |
Hyunsun Moon | dd14e8e | 2016-06-09 16:17:32 -0700 | [diff] [blame] | 32 | import java.util.Collections; |
Andrea Campanella | 238d96e | 2016-01-20 11:52:02 -0800 | [diff] [blame] | 33 | |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 34 | /** |
| 35 | * OVSDB-based implementation of tunnel config behaviour. |
Hyunsun Moon | dd14e8e | 2016-06-09 16:17:32 -0700 | [diff] [blame] | 36 | * |
| 37 | * @deprecated version 1.7.0 - Hummingbird; use interface config instead |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 38 | */ |
Hyunsun Moon | dd14e8e | 2016-06-09 16:17:32 -0700 | [diff] [blame] | 39 | @Deprecated |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 40 | public class OvsdbTunnelConfig extends AbstractHandlerBehaviour |
| 41 | implements TunnelConfig { |
| 42 | |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 43 | @Override |
Hyunsun Moon | aab8c67 | 2015-10-27 19:42:12 -0700 | [diff] [blame] | 44 | public boolean createTunnelInterface(BridgeName bridgeName, TunnelDescription tunnel) { |
Hyunsun Moon | aab8c67 | 2015-10-27 19:42:12 -0700 | [diff] [blame] | 45 | DriverHandler handler = handler(); |
Hyunsun Moon | dd14e8e | 2016-06-09 16:17:32 -0700 | [diff] [blame] | 46 | OvsdbClientService ovsdbNode = getOvsdbNode(handler); |
| 47 | |
| 48 | OvsdbInterface ovsdbIface = OvsdbInterface.builder(tunnel).build(); |
| 49 | return ovsdbNode.createInterface(bridgeName.name(), ovsdbIface); |
Hyunsun Moon | aab8c67 | 2015-10-27 19:42:12 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | @Override |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 53 | public void removeTunnel(TunnelDescription tunnel) { |
| 54 | DriverHandler handler = handler(); |
| 55 | OvsdbClientService ovsdbNode = getOvsdbNode(handler); |
Hyunsun Moon | dd14e8e | 2016-06-09 16:17:32 -0700 | [diff] [blame] | 56 | ovsdbNode.dropInterface(tunnel.ifaceName()); |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 57 | } |
| 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 Moon | dd14e8e | 2016-06-09 16:17:32 -0700 | [diff] [blame] | 67 | return Collections.emptyList(); |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 68 | } |
| 69 | |
jiangrui | 866c2f2 | 2015-10-28 18:58:34 +0800 | [diff] [blame] | 70 | // OvsdbNodeId(IP) is used in the adaptor while DeviceId(ovsdb:IP) |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 71 | // is used in the core. So DeviceId need be changed to OvsdbNodeId. |
| 72 | private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) { |
jiangrui | 866c2f2 | 2015-10-28 18:58:34 +0800 | [diff] [blame] | 73 | String[] splits = deviceId.toString().split(":"); |
| 74 | if (splits == null || splits.length < 1) { |
| 75 | return null; |
| 76 | } |
Hyunsun Moon | dbab8de | 2015-10-28 16:45:04 -0700 | [diff] [blame] | 77 | IpAddress ipAddress = IpAddress.valueOf(splits[1]); |
jiangrui | 866c2f2 | 2015-10-28 18:58:34 +0800 | [diff] [blame] | 78 | return new OvsdbNodeId(ipAddress, 0); |
samuel | bc087c0 | 2015-07-23 14:11:58 +0800 | [diff] [blame] | 79 | } |
| 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 | } |