Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-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.bmv2; |
| 18 | |
| 19 | import org.onosproject.net.MastershipRole; |
| 20 | import org.onosproject.net.device.DeviceHandshaker; |
| 21 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 22 | import org.onosproject.net.driver.DriverData; |
| 23 | import org.onosproject.net.key.DeviceKeyId; |
| 24 | import org.onosproject.net.key.DeviceKeyService; |
| 25 | import org.slf4j.Logger; |
| 26 | |
| 27 | import java.util.concurrent.CompletableFuture; |
| 28 | |
| 29 | import static org.slf4j.LoggerFactory.getLogger; |
| 30 | |
| 31 | /** |
| 32 | * Implementation of the DeviceHandshaker for the bmv2 softswitch. |
| 33 | */ |
| 34 | //TODO consider abstract class with empty connect method and |
| 35 | //the implementation into a protected one for reusability. |
| 36 | //FIXME fill method bodies, used for testing. |
| 37 | public class Bmv2Handshaker extends AbstractHandlerBehaviour |
| 38 | implements DeviceHandshaker { |
| 39 | |
| 40 | private final Logger log = getLogger(getClass()); |
| 41 | |
| 42 | @Override |
| 43 | public CompletableFuture<Boolean> connect() { |
| 44 | CompletableFuture<Boolean> result = new CompletableFuture<>(); |
| 45 | DeviceKeyService deviceKeyService = handler().get(DeviceKeyService.class); |
| 46 | DriverData data = data(); |
| 47 | //Retrieving information from the driver data. |
| 48 | log.info("protocol bmv2, ip {}, port {}, key {}", data.value("p4runtime_ip"), |
| 49 | data.value("p4runtime_port"), |
| 50 | deviceKeyService.getDeviceKey(DeviceKeyId.deviceKeyId(data.value("p4runtime_key"))) |
| 51 | .asUsernamePassword().username()); |
| 52 | |
| 53 | log.info("protocol gnmi, ip {}, port {}, key {}", data.value("gnmi_ip"), data.value("gnmi_port"), |
| 54 | deviceKeyService.getDeviceKey(DeviceKeyId.deviceKeyId(data.value("gnmi_key"))) |
| 55 | .asUsernamePassword().username()); |
| 56 | result.complete(true); |
| 57 | return result; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public CompletableFuture<Boolean> disconnect() { |
| 62 | CompletableFuture<Boolean> result = new CompletableFuture<>(); |
| 63 | result.complete(true); |
| 64 | return result; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public CompletableFuture<Boolean> isReachable() { |
| 69 | CompletableFuture<Boolean> result = new CompletableFuture<>(); |
| 70 | result.complete(true); |
| 71 | return result; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public CompletableFuture<MastershipRole> roleChanged(MastershipRole newRole) { |
| 76 | CompletableFuture<MastershipRole> result = new CompletableFuture<>(); |
| 77 | result.complete(MastershipRole.MASTER); |
| 78 | return result; |
| 79 | } |
| 80 | |
| 81 | } |