blob: c206696a8e4e52c26dd6e5ec3cb62a5f8f5c6952 [file] [log] [blame]
Palash Kalac99b15a2017-06-14 09:36:56 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Palash Kalac99b15a2017-06-14 09:36:56 +09003 *
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.arista;
18
DongRyeol Cha06041fa2018-06-07 10:23:32 +090019import com.google.common.collect.Lists;
Palash Kalac99b15a2017-06-14 09:36:56 +090020import org.onosproject.net.behaviour.ControllerConfig;
21import org.onosproject.net.behaviour.ControllerInfo;
22import org.onosproject.net.driver.AbstractHandlerBehaviour;
Palash Kalac99b15a2017-06-14 09:36:56 +090023import org.slf4j.Logger;
24
Palash Kalac99b15a2017-06-14 09:36:56 +090025import java.util.List;
26
Palash Kalac99b15a2017-06-14 09:36:56 +090027import static org.slf4j.LoggerFactory.getLogger;
28
29/**
30 * Sets, gets and removes the openflow controller configuration from a Arista Rest device.
31 */
32public class ControllerConfigAristaImpl extends AbstractHandlerBehaviour implements ControllerConfig {
33
34 private static final String CONFIGURE_TERMINAL = "configure";
35 private static final String OPENFLOW_CMD = "openflow";
36 private static final String REMOVE_CONTROLLER_CMD = "no controller tcp:%s:%d";
Palash Kalac99b15a2017-06-14 09:36:56 +090037 private static final int MAX_CONTROLLERS = 8;
Palash Kalac99b15a2017-06-14 09:36:56 +090038
39 private final Logger log = getLogger(getClass());
40
41 @Override
42 public List<ControllerInfo> getControllers() {
43 throw new UnsupportedOperationException("get controllers configuration is not supported");
44 }
45
46 @Override
47 public void setControllers(List<ControllerInfo> controllers) {
48 throw new UnsupportedOperationException("set controllers configuration is not supported");
49 }
50
51 @Override
52 public void removeControllers(List<ControllerInfo> controllers) {
DongRyeol Cha06041fa2018-06-07 10:23:32 +090053 List<String> cmds = Lists.newArrayList();
Palash Kalac99b15a2017-06-14 09:36:56 +090054
Palash Kalac99b15a2017-06-14 09:36:56 +090055 cmds.add(CONFIGURE_TERMINAL);
56 cmds.add(OPENFLOW_CMD);
57 controllers.stream().limit(MAX_CONTROLLERS).forEach(c -> cmds
58 .add(String.format(REMOVE_CONTROLLER_CMD, c.ip().toString(), c.port())));
59
DongRyeol Cha06041fa2018-06-07 10:23:32 +090060 AristaUtils.retrieveCommandResult(handler(), cmds);
Palash Kalac99b15a2017-06-14 09:36:56 +090061 }
62}