blob: 2256d5efdb0f507697e731171726eb78b56f10ba [file] [log] [blame]
Carmelo Casconef7aa3f92017-07-06 23:56:50 -04001/*
Carmelo Cascone4c289b72019-01-22 15:30:45 -08002 * Copyright 2019-present Open Networking Foundation
Carmelo Casconef7aa3f92017-07-06 23:56:50 -04003 *
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 Cascone4c289b72019-01-22 15:30:45 -080017package org.onosproject.p4runtime.ctl.controller;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040018
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040019import io.grpc.ManagedChannel;
Yi Tseng2a340f72018-11-02 16:52:47 -070020import org.onosproject.grpc.ctl.AbstractGrpcClientController;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040021import org.onosproject.net.DeviceId;
Carmelo Cascone4c289b72019-01-22 15:30:45 -080022import org.onosproject.net.pi.service.PiPipeconfService;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040023import org.onosproject.p4runtime.api.P4RuntimeClient;
Yi Tseng2a340f72018-11-02 16:52:47 -070024import org.onosproject.p4runtime.api.P4RuntimeClientKey;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040025import org.onosproject.p4runtime.api.P4RuntimeController;
26import org.onosproject.p4runtime.api.P4RuntimeEvent;
27import org.onosproject.p4runtime.api.P4RuntimeEventListener;
Carmelo Cascone4c289b72019-01-22 15:30:45 -080028import org.onosproject.p4runtime.ctl.client.P4RuntimeClientImpl;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070029import org.osgi.service.component.annotations.Component;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070030import org.osgi.service.component.annotations.Reference;
31import org.osgi.service.component.annotations.ReferenceCardinality;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040032
33/**
34 * P4Runtime controller implementation.
35 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070036@Component(immediate = true, service = P4RuntimeController.class)
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040037public class P4RuntimeControllerImpl
Yi Tseng2a340f72018-11-02 16:52:47 -070038 extends AbstractGrpcClientController
39 <P4RuntimeClientKey, P4RuntimeClient, P4RuntimeEvent, P4RuntimeEventListener>
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040040 implements P4RuntimeController {
41
Carmelo Cascone4c289b72019-01-22 15:30:45 -080042 @Reference(cardinality = ReferenceCardinality.MANDATORY)
43 private PiPipeconfService pipeconfService;
44
Carmelo Cascone3977ea42019-02-28 13:43:42 -080045 @Reference(cardinality = ReferenceCardinality.MANDATORY)
46 private MasterElectionIdStore masterElectionIdStore;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040047
Carmelo Cascone3977ea42019-02-28 13:43:42 -080048 public P4RuntimeControllerImpl() {
49 super(P4RuntimeEvent.class);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040050 }
51
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040052 @Override
Carmelo Cascone3977ea42019-02-28 13:43:42 -080053 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 Casconef7aa3f92017-07-06 23:56:50 -040058 }
59
Yi Tseng3e7f1452017-10-20 10:31:53 -070060 @Override
Carmelo Cascone3977ea42019-02-28 13:43:42 -080061 public void removeClient(P4RuntimeClientKey clientKey) {
62 super.removeClient(clientKey);
63 masterElectionIdStore.remove(clientKey.deviceId());
Yi Tseng3e7f1452017-10-20 10:31:53 -070064 }
65
Andrea Campanella1e573442018-05-17 17:07:13 +020066 @Override
Carmelo Cascone3977ea42019-02-28 13:43:42 -080067 protected P4RuntimeClient createClientInstance(
68 P4RuntimeClientKey clientKey, ManagedChannel channel) {
69 return new P4RuntimeClientImpl(clientKey, channel, this,
70 pipeconfService, masterElectionIdStore);
Carmelo Casconee5b28722018-06-22 17:28:28 +020071 }
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040072}