HelloONOS | 0854c04 | 2019-02-18 20:09:17 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-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 | */ |
| 16 | |
| 17 | package org.onosproject.drivers.arista; |
| 18 | |
| 19 | |
| 20 | import static org.slf4j.LoggerFactory.getLogger; |
| 21 | |
| 22 | import java.util.ArrayList; |
| 23 | import java.util.Collection; |
| 24 | import java.util.List; |
| 25 | import java.util.Set; |
| 26 | |
| 27 | import org.onosproject.net.PortNumber; |
| 28 | import org.onosproject.net.behaviour.BridgeConfig; |
| 29 | import org.onosproject.net.behaviour.BridgeDescription; |
| 30 | import org.onosproject.net.behaviour.BridgeName; |
| 31 | import org.onosproject.net.device.PortDescription; |
| 32 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 33 | import org.slf4j.Logger; |
| 34 | |
| 35 | public class BridgeConfigAristaImpl extends AbstractHandlerBehaviour implements BridgeConfig { |
| 36 | private final Logger log = getLogger(getClass()); |
| 37 | |
| 38 | private static final String CONFIGURE_TERMINAL = "configure"; |
| 39 | private static final String OPENFLOW_CMD = "openflow"; |
| 40 | private static final String BIND_CMD = "bind interface %s"; |
| 41 | private static final String NO_BIND_CMD = "no bind interface %s"; |
| 42 | private static final String INTERFACE_CMD = "interface %s"; |
| 43 | private static final String NO_SPEED = "no speed"; |
| 44 | private static final String SPEED_40G_FULL_CMD = "speed forced 40gfull"; |
| 45 | |
| 46 | |
| 47 | @Override |
| 48 | public boolean addBridge(BridgeDescription bridgeDescription) { |
| 49 | log.warn("addBridge is not supported"); |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public void deleteBridge(BridgeName bridgeName) { |
| 55 | log.warn("deleteBridge is not supported"); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public Collection<BridgeDescription> getBridges() { |
| 60 | log.warn("deleteBridge is not supported"); |
| 61 | return null; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public void addPort(BridgeName bridgeName, String portName) { |
| 66 | List<String> cmds = new ArrayList<>(); |
| 67 | cmds.add(CONFIGURE_TERMINAL); |
| 68 | cmds.add(OPENFLOW_CMD); |
| 69 | cmds.add(String.format(BIND_CMD, portName)); |
| 70 | |
| 71 | AristaUtils.getWithChecking(handler(), cmds); |
| 72 | } |
| 73 | |
| 74 | @Override |
HelloONOS | acd86360 | 2019-07-31 18:23:25 +0900 | [diff] [blame] | 75 | public void addPorts(BridgeName bridgeName, List<String> portNames) { |
| 76 | List<String> cmds = new ArrayList<>(); |
| 77 | cmds.add(CONFIGURE_TERMINAL); |
| 78 | cmds.add(OPENFLOW_CMD); |
| 79 | for (String portName : portNames) { |
| 80 | cmds.add(String.format(BIND_CMD, portName)); |
| 81 | } |
| 82 | |
| 83 | AristaUtils.getWithChecking(handler(), cmds); |
| 84 | } |
| 85 | |
| 86 | @Override |
HelloONOS | 0854c04 | 2019-02-18 20:09:17 +0900 | [diff] [blame] | 87 | public void deletePort(BridgeName bridgeName, String portName) { |
| 88 | List<String> cmds = new ArrayList<>(); |
| 89 | cmds.add(CONFIGURE_TERMINAL); |
| 90 | cmds.add(OPENFLOW_CMD); |
| 91 | cmds.add(String.format(NO_BIND_CMD, portName)); |
| 92 | |
| 93 | AristaUtils.getWithChecking(handler(), cmds); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void deletePorts(BridgeName bridgeName, List<String> portNames) { |
| 98 | List<String> cmds = new ArrayList<>(); |
| 99 | cmds.add(CONFIGURE_TERMINAL); |
| 100 | cmds.add(OPENFLOW_CMD); |
| 101 | for (String portName : portNames) { |
| 102 | cmds.add(String.format(NO_BIND_CMD, portName)); |
| 103 | } |
| 104 | |
| 105 | AristaUtils.getWithChecking(handler(), cmds); |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public Collection<PortDescription> getPorts() { |
| 110 | // TODO need to implement |
| 111 | log.warn("not implemented yet"); |
| 112 | return null; |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public Set<PortNumber> getPortNumbers() { |
| 117 | // TODO need to implement |
| 118 | log.warn("not implemented yet"); |
| 119 | return null; |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public List<PortNumber> getLocalPorts(Iterable<String> ifaceIds) { |
| 124 | // TODO need to implement |
| 125 | log.warn("not implemented yet"); |
| 126 | return null; |
| 127 | } |
| 128 | } |