blob: 414d9e2e62401de38a4dbf08320c124cbb12480e [file] [log] [blame]
Andrea Campanella6ee73922016-02-03 18:00:00 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Andrea Campanella6ee73922016-02-03 18:00:00 -08003 *
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.net.group.impl;
18
Andrea Campanellae4273902016-02-08 13:43:30 -080019import org.onosproject.net.Device;
Andrea Campanella6ee73922016-02-03 18:00:00 -080020import org.onosproject.net.DeviceId;
21import org.onosproject.net.device.DeviceService;
22import org.onosproject.net.group.GroupOperations;
23import org.onosproject.net.group.GroupProgrammable;
24import org.onosproject.net.group.GroupProvider;
25import org.onosproject.net.provider.AbstractProvider;
26import org.onosproject.net.provider.ProviderId;
27import org.slf4j.Logger;
28import org.slf4j.LoggerFactory;
29
30/**
31 * Driver-based Group rule provider.
32 */
33public class GroupDriverProvider extends AbstractProvider implements GroupProvider {
34
35 private final Logger log = LoggerFactory.getLogger(getClass());
36
37 // To be extracted for reuse as we deal with other.
38 private static final String SCHEME = "default";
39 private static final String PROVIDER_NAME = "org.onosproject.provider";
40 protected DeviceService deviceService;
41
42 public GroupDriverProvider() {
43 super(new ProviderId(SCHEME, PROVIDER_NAME));
44 }
45
46 /**
47 * Initializes the provider with the necessary device service.
48 *
49 * @param deviceService device service
50 */
51 void init(DeviceService deviceService) {
52 this.deviceService = deviceService;
53 }
54
55 @Override
56 public void performGroupOperation(DeviceId deviceId, GroupOperations groupOps) {
57 GroupProgrammable programmable = getGroupProgrammable(deviceId);
58 if (programmable != null) {
59 programmable.performGroupOperation(deviceId, groupOps);
60 }
61 }
62
63 private GroupProgrammable getGroupProgrammable(DeviceId deviceId) {
Andrea Campanellae4273902016-02-08 13:43:30 -080064 Device device = deviceService.getDevice(deviceId);
65 if (device.is(GroupProgrammable.class)) {
66 return device.as(GroupProgrammable.class);
67 } else {
Andrea Campanellafe1d4732016-02-08 16:45:27 -080068 log.debug("Device {} is not group programmable", deviceId);
Andrea Campanellae4273902016-02-08 13:43:30 -080069 return null;
Andrea Campanella6ee73922016-02-03 18:00:00 -080070 }
Andrea Campanella6ee73922016-02-03 18:00:00 -080071 }
72}