Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 1 | /* |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 2 | * Copyright 2019-present Open Networking Foundation |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 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 | |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 17 | package org.onosproject.p4runtime.ctl.controller; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 18 | |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 19 | import io.grpc.ManagedChannel; |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 20 | import org.onosproject.grpc.ctl.AbstractGrpcClientController; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 21 | import org.onosproject.net.DeviceId; |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 22 | import org.onosproject.net.pi.service.PiPipeconfService; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 23 | import org.onosproject.p4runtime.api.P4RuntimeClient; |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 24 | import org.onosproject.p4runtime.api.P4RuntimeClientKey; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 25 | import org.onosproject.p4runtime.api.P4RuntimeController; |
| 26 | import org.onosproject.p4runtime.api.P4RuntimeEvent; |
| 27 | import org.onosproject.p4runtime.api.P4RuntimeEventListener; |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 28 | import org.onosproject.p4runtime.ctl.client.P4RuntimeClientImpl; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 29 | import org.osgi.service.component.annotations.Component; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 30 | import org.osgi.service.component.annotations.Reference; |
| 31 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * P4Runtime controller implementation. |
| 35 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 36 | @Component(immediate = true, service = P4RuntimeController.class) |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 37 | public class P4RuntimeControllerImpl |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 38 | extends AbstractGrpcClientController |
| 39 | <P4RuntimeClientKey, P4RuntimeClient, P4RuntimeEvent, P4RuntimeEventListener> |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 40 | implements P4RuntimeController { |
| 41 | |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 42 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 43 | private PiPipeconfService pipeconfService; |
| 44 | |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame^] | 45 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 46 | private MasterElectionIdStore masterElectionIdStore; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 47 | |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame^] | 48 | public P4RuntimeControllerImpl() { |
| 49 | super(P4RuntimeEvent.class); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 50 | } |
| 51 | |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 52 | @Override |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame^] | 53 | public void removeClient(DeviceId deviceId) { |
| 54 | super.removeClient(deviceId); |
| 55 | // Assuming that when a client is removed, it is done so by all nodes, |
| 56 | // this is the best place to clear master election ID state. |
| 57 | masterElectionIdStore.remove(deviceId); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 58 | } |
| 59 | |
Yi Tseng | 3e7f145 | 2017-10-20 10:31:53 -0700 | [diff] [blame] | 60 | @Override |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame^] | 61 | public void removeClient(P4RuntimeClientKey clientKey) { |
| 62 | super.removeClient(clientKey); |
| 63 | masterElectionIdStore.remove(clientKey.deviceId()); |
Yi Tseng | 3e7f145 | 2017-10-20 10:31:53 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Andrea Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 66 | @Override |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame^] | 67 | protected P4RuntimeClient createClientInstance( |
| 68 | P4RuntimeClientKey clientKey, ManagedChannel channel) { |
| 69 | return new P4RuntimeClientImpl(clientKey, channel, this, |
| 70 | pipeconfService, masterElectionIdStore); |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 71 | } |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 72 | } |