Hyunsun Moon | dd14e8e | 2016-06-09 16:17:32 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | */ |
| 16 | |
| 17 | package org.onosproject.drivers.ovsdb; |
| 18 | |
| 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.VlanId; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.behaviour.InterfaceConfig; |
| 23 | import org.onosproject.net.behaviour.TunnelDescription; |
| 24 | import org.onosproject.net.device.DeviceInterfaceDescription; |
| 25 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 26 | import org.onosproject.net.driver.DriverHandler; |
| 27 | import org.onosproject.ovsdb.controller.OvsdbClientService; |
| 28 | import org.onosproject.ovsdb.controller.OvsdbController; |
| 29 | import org.onosproject.ovsdb.controller.OvsdbInterface; |
| 30 | import org.onosproject.ovsdb.controller.OvsdbNodeId; |
| 31 | import org.slf4j.Logger; |
| 32 | |
| 33 | import java.util.List; |
| 34 | |
| 35 | import static org.slf4j.LoggerFactory.getLogger; |
| 36 | |
| 37 | /** |
| 38 | * OVSDB-based implementation of interface config behaviour. |
| 39 | */ |
| 40 | public class OvsdbInterfaceConfig extends AbstractHandlerBehaviour implements InterfaceConfig { |
| 41 | |
| 42 | private final Logger log = getLogger(getClass()); |
| 43 | |
| 44 | @Override |
| 45 | public boolean addTunnelMode(String ifaceName, TunnelDescription tunnelDesc) { |
| 46 | OvsdbInterface ovsdbIface = OvsdbInterface.builder(tunnelDesc).build(); |
| 47 | OvsdbClientService ovsdbClient = getOvsdbClient(handler()); |
| 48 | |
| 49 | if (!tunnelDesc.deviceId().isPresent()) { |
| 50 | log.warn("Device ID is required {}", tunnelDesc); |
| 51 | return false; |
| 52 | } |
| 53 | return ovsdbClient.createInterface(tunnelDesc.deviceId().get(), ovsdbIface); |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public boolean removeTunnelMode(String ifaceName) { |
| 58 | OvsdbClientService ovsdbClient = getOvsdbClient(handler()); |
| 59 | return ovsdbClient.dropInterface(ifaceName); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public boolean addAccessMode(String ifaceName, VlanId vlanId) { |
| 64 | // TODO implement |
| 65 | throw new UnsupportedOperationException("Not implemented yet"); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public boolean removeAccessMode(String ifaceName) { |
| 70 | // TODO implement |
| 71 | throw new UnsupportedOperationException("Not implemented yet"); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public boolean addTrunkMode(String ifaceName, List<VlanId> vlanIds) { |
| 76 | // TODO implement |
| 77 | throw new UnsupportedOperationException("Not implemented yet"); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public boolean removeTrunkMode(String ifaceName) { |
| 82 | // TODO implement |
| 83 | throw new UnsupportedOperationException("Not implemented yet"); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public boolean addRateLimit(String ifaceName, short limit) { |
| 88 | // TODO implement |
| 89 | throw new UnsupportedOperationException("Not implemented yet"); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public boolean removeRateLimit(String ifaceName) { |
| 94 | // TODO implement |
| 95 | throw new UnsupportedOperationException("Not implemented yet"); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public List<DeviceInterfaceDescription> getInterfaces() { |
| 100 | // TODO implement |
| 101 | throw new UnsupportedOperationException("Not implemented yet"); |
| 102 | } |
| 103 | |
| 104 | // deprecated interfaces |
| 105 | @Override |
| 106 | public boolean addAccessInterface(DeviceId deviceId, String ifaceName, VlanId vlanId) { |
| 107 | throw new UnsupportedOperationException("Not implemented yet"); |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public boolean removeAccessInterface(DeviceId deviceId, String ifaceName) { |
| 112 | throw new UnsupportedOperationException("Not implemented yet"); |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public boolean addTrunkInterface(DeviceId deviceId, String ifaceName, List<VlanId> vlanIds) { |
| 117 | throw new UnsupportedOperationException("Not implemented yet"); |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public List<DeviceInterfaceDescription> getInterfaces(DeviceId deviceId) { |
| 122 | return null; |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public boolean removeTrunkInterface(DeviceId deviceId, String ifaceName) { |
| 127 | throw new UnsupportedOperationException("Not implemented yet"); |
| 128 | } |
| 129 | |
| 130 | // OvsdbNodeId(IP) is used in the adaptor while DeviceId(ovsdb:IP) |
| 131 | // is used in the core. So DeviceId need be changed to OvsdbNodeId. |
| 132 | private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) { |
| 133 | String[] splits = deviceId.toString().split(":"); |
| 134 | if (splits.length < 1) { |
| 135 | return null; |
| 136 | } |
| 137 | IpAddress ipAddress = IpAddress.valueOf(splits[1]); |
| 138 | return new OvsdbNodeId(ipAddress, 0); |
| 139 | } |
| 140 | |
| 141 | private OvsdbClientService getOvsdbClient(DriverHandler handler) { |
| 142 | OvsdbController ovsController = handler.get(OvsdbController.class); |
| 143 | OvsdbNodeId nodeId = changeDeviceIdToNodeId(handler.data().deviceId()); |
| 144 | |
| 145 | return ovsController.getOvsdbClient(nodeId); |
| 146 | } |
| 147 | } |