blob: ac9a534599a945e37a039434204df93411fb6638 [file] [log] [blame]
Yi Tsengd7716482018-10-31 15:34:30 -07001/*
2 * Copyright 2018-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
17package org.onosproject.drivers.stratum;
18
Yi Tsengd7716482018-10-31 15:34:30 -070019import org.onosproject.drivers.gnmi.GnmiHandshaker;
oleksandr.yashchuk@plvision.eu3dbcaaf2019-03-13 14:44:46 +020020import org.onosproject.drivers.gnoi.GnoiHandshaker;
Yi Tsengd7716482018-10-31 15:34:30 -070021import org.onosproject.drivers.p4runtime.P4RuntimeHandshaker;
Yi Tsengd7716482018-10-31 15:34:30 -070022import org.onosproject.net.MastershipRole;
23import org.onosproject.net.device.DeviceAgentListener;
24import org.onosproject.net.device.DeviceHandshaker;
Yi Tsengd7716482018-10-31 15:34:30 -070025import org.onosproject.net.provider.ProviderId;
Yi Tsengd7716482018-10-31 15:34:30 -070026
27import java.util.concurrent.CompletableFuture;
Yi Tsengd7716482018-10-31 15:34:30 -070028
29/**
30 * Implementation of DeviceHandshaker for Stratum device.
31 */
Carmelo Casconeab5d41e2019-03-06 18:02:34 -080032public class StratumHandshaker
33 extends AbstractStratumBehaviour<DeviceHandshaker>
34 implements DeviceHandshaker {
Yi Tsengd7716482018-10-31 15:34:30 -070035
36 public StratumHandshaker() {
oleksandr.yashchuk@plvision.eu3dbcaaf2019-03-13 14:44:46 +020037 super(new P4RuntimeHandshaker(), new GnmiHandshaker(), new GnoiHandshaker());
Yi Tsengd7716482018-10-31 15:34:30 -070038 }
39
40 @Override
Carmelo Casconec2be50a2019-04-10 00:15:39 -070041 public boolean connect() {
42 return p4runtime.connect() && gnmi.connect() && gnoi.connect();
43 }
44
45 @Override
46 public boolean hasConnection() {
47 return p4runtime.hasConnection() && gnmi.hasConnection() && gnoi.hasConnection();
48 }
49
50 @Override
51 public void disconnect() {
52 p4runtime.disconnect();
53 gnmi.disconnect();
54 gnoi.disconnect();
55 }
56
57 @Override
Carmelo Cascone3977ea42019-02-28 13:43:42 -080058 public boolean isReachable() {
Carmelo Casconeab5d41e2019-03-06 18:02:34 -080059 // Reachability is mainly used for mastership contests and it's a
60 // prerequisite for availability. We can probably live without gNMI and
61 // gNOI, but we will always need P4Runtime.
62 return p4runtime.isReachable();
Carmelo Cascone3977ea42019-02-28 13:43:42 -080063 }
64
65 @Override
66 public CompletableFuture<Boolean> probeReachability() {
67 return p4runtime.probeReachability();
68 }
69
70 @Override
71 public boolean isAvailable() {
72 // Availability concerns packet forwarding, hence we consider only
73 // P4Runtime.
74 return p4runtime.isAvailable();
75 }
76
77 @Override
78 public CompletableFuture<Boolean> probeAvailability() {
79 return p4runtime.probeAvailability();
Yi Tsengd7716482018-10-31 15:34:30 -070080 }
81
82 @Override
83 public void roleChanged(MastershipRole newRole) {
Carmelo Cascone3977ea42019-02-28 13:43:42 -080084 p4runtime.roleChanged(newRole);
85 }
86
87 @Override
88 public void roleChanged(int preference, long term) {
89 p4runtime.roleChanged(preference, term);
Yi Tsengd7716482018-10-31 15:34:30 -070090 }
91
92 @Override
93 public MastershipRole getRole() {
Carmelo Cascone3977ea42019-02-28 13:43:42 -080094 return p4runtime.getRole();
Yi Tsengd7716482018-10-31 15:34:30 -070095 }
96
97 @Override
98 public void addDeviceAgentListener(ProviderId providerId, DeviceAgentListener listener) {
Carmelo Cascone3977ea42019-02-28 13:43:42 -080099 p4runtime.addDeviceAgentListener(providerId, listener);
Yi Tsengd7716482018-10-31 15:34:30 -0700100 }
101
102 @Override
103 public void removeDeviceAgentListener(ProviderId providerId) {
Carmelo Cascone3977ea42019-02-28 13:43:42 -0800104 p4runtime.removeDeviceAgentListener(providerId);
Yi Tsengd7716482018-10-31 15:34:30 -0700105 }
Yi Tsengd7716482018-10-31 15:34:30 -0700106}