blob: e8b86581d45c8e040ae34be0b5160bd433f0347d [file] [log] [blame]
Yi Tseng3e7f1452017-10-20 10:31:53 -07001/*
2 * Copyright 2017-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.p4runtime.ctl;
18
Andrea Campanella1e573442018-05-17 17:07:13 +020019import org.onosproject.net.DeviceId;
Yi Tseng3e7f1452017-10-20 10:31:53 -070020import org.onosproject.net.MastershipRole;
21import org.onosproject.p4runtime.api.P4RuntimeEventSubject;
Carmelo Cascone6af4e172018-06-15 16:01:30 +020022import p4.v1.P4RuntimeOuterClass.Uint128;
Yi Tseng3e7f1452017-10-20 10:31:53 -070023
24/**
25 * Default implementation of arbitration in P4Runtime.
26 */
27public class DefaultArbitration implements P4RuntimeEventSubject {
28 private MastershipRole role;
29 private Uint128 electionId;
Andrea Campanella1e573442018-05-17 17:07:13 +020030 private DeviceId deviceId;
Yi Tseng3e7f1452017-10-20 10:31:53 -070031
32 /**
33 * Creates arbitration with given role and election id.
34 *
Andrea Campanella1e573442018-05-17 17:07:13 +020035 * @param deviceId the device
36 * @param role the role
Yi Tseng3e7f1452017-10-20 10:31:53 -070037 * @param electionId the election id
38 */
Carmelo Cascone6af4e172018-06-15 16:01:30 +020039 DefaultArbitration(DeviceId deviceId, MastershipRole role, Uint128 electionId) {
Andrea Campanella1e573442018-05-17 17:07:13 +020040 this.deviceId = deviceId;
Yi Tseng3e7f1452017-10-20 10:31:53 -070041 this.role = role;
42 this.electionId = electionId;
43 }
44
45 /**
46 * Gets the role of this arbitration.
47 *
48 * @return the role
49 */
50 public MastershipRole role() {
51 return role;
52 }
53
54 /**
55 * Gets election id of this arbitration.
56 *
57 * @return the election id
58 */
59 public Uint128 electionId() {
60 return electionId;
61 }
Andrea Campanella1e573442018-05-17 17:07:13 +020062
63 @Override
64 public DeviceId deviceId() {
65 return deviceId;
66 }
Yi Tseng3e7f1452017-10-20 10:31:53 -070067}