Yi Tseng | 3e7f145 | 2017-10-20 10:31:53 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.p4runtime.ctl; |
| 18 | |
Andrea Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 19 | import org.onosproject.net.DeviceId; |
Yi Tseng | 3e7f145 | 2017-10-20 10:31:53 -0700 | [diff] [blame] | 20 | import org.onosproject.net.MastershipRole; |
| 21 | import org.onosproject.p4runtime.api.P4RuntimeEventSubject; |
| 22 | import p4.P4RuntimeOuterClass.Uint128; |
| 23 | |
| 24 | /** |
| 25 | * Default implementation of arbitration in P4Runtime. |
| 26 | */ |
| 27 | public class DefaultArbitration implements P4RuntimeEventSubject { |
| 28 | private MastershipRole role; |
| 29 | private Uint128 electionId; |
Andrea Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 30 | private DeviceId deviceId; |
Yi Tseng | 3e7f145 | 2017-10-20 10:31:53 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Creates arbitration with given role and election id. |
| 34 | * |
Andrea Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 35 | * @param deviceId the device |
| 36 | * @param role the role |
Yi Tseng | 3e7f145 | 2017-10-20 10:31:53 -0700 | [diff] [blame] | 37 | * @param electionId the election id |
| 38 | */ |
Andrea Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 39 | public DefaultArbitration(DeviceId deviceId, MastershipRole role, Uint128 electionId) { |
| 40 | this.deviceId = deviceId; |
Yi Tseng | 3e7f145 | 2017-10-20 10:31:53 -0700 | [diff] [blame] | 41 | 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 Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 62 | |
| 63 | @Override |
| 64 | public DeviceId deviceId() { |
| 65 | return deviceId; |
| 66 | } |
Yi Tseng | 3e7f145 | 2017-10-20 10:31:53 -0700 | [diff] [blame] | 67 | } |