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