blob: 06f9c9e1230b87ef80ff506fddd046e8a1fccf52 [file] [log] [blame]
Andrea Campanella241896c2017-05-10 13:11:04 -07001/*
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
17package org.onosproject.drivers.bmv2;
18
19import org.onosproject.net.MastershipRole;
20import org.onosproject.net.device.DeviceHandshaker;
21import org.onosproject.net.driver.AbstractHandlerBehaviour;
22import org.onosproject.net.driver.DriverData;
23import org.onosproject.net.key.DeviceKeyId;
24import org.onosproject.net.key.DeviceKeyService;
25import org.slf4j.Logger;
26
27import java.util.concurrent.CompletableFuture;
28
29import 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.
37public 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}