Andrea Campanella
Committed by Gerrit Code Review

ONOS-3759 Group default provider

Change-Id: I318c8036a1836d13f57187bfd28464c740e09f08
1 +/*
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 +
17 +package org.onosproject.net.group;
18 +
19 +import org.onosproject.net.DeviceId;
20 +import org.onosproject.net.driver.HandlerBehaviour;
21 +
22 +/**
23 + * Group programmable device behaviour.
24 + */
25 +public interface GroupProgrammable extends HandlerBehaviour {
26 +
27 + /**
28 + * Performs the Group operations for the specified device.
29 + *
30 + * @param deviceId ID of the device
31 + * @param groupOps operations to be performed
32 + */
33 + void performGroupOperation(DeviceId deviceId, GroupOperations groupOps);
34 +}
1 +/*
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 +
17 +package org.onosproject.net.group.impl;
18 +
19 +import org.onosproject.net.DeviceId;
20 +import org.onosproject.net.device.DeviceService;
21 +import org.onosproject.net.group.GroupOperations;
22 +import org.onosproject.net.group.GroupProgrammable;
23 +import org.onosproject.net.group.GroupProvider;
24 +import org.onosproject.net.provider.AbstractProvider;
25 +import org.onosproject.net.provider.ProviderId;
26 +import org.slf4j.Logger;
27 +import org.slf4j.LoggerFactory;
28 +
29 +/**
30 + * Driver-based Group rule provider.
31 + */
32 +public 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 +}
...@@ -87,6 +87,7 @@ public class GroupManager ...@@ -87,6 +87,7 @@ public class GroupManager
87 @Property(name = "purgeOnDisconnection", boolValue = false, 87 @Property(name = "purgeOnDisconnection", boolValue = false,
88 label = "Purge entries associated with a device when the device goes offline") 88 label = "Purge entries associated with a device when the device goes offline")
89 private boolean purgeOnDisconnection = false; 89 private boolean purgeOnDisconnection = false;
90 + private final GroupDriverProvider defaultProvider = new GroupDriverProvider();
90 91
91 @Activate 92 @Activate
92 public void activate(ComponentContext context) { 93 public void activate(ComponentContext context) {
...@@ -111,6 +112,12 @@ public class GroupManager ...@@ -111,6 +112,12 @@ public class GroupManager
111 if (context != null) { 112 if (context != null) {
112 readComponentConfiguration(context); 113 readComponentConfiguration(context);
113 } 114 }
115 + defaultProvider.init(deviceService);
116 + }
117 +
118 + @Override
119 + protected GroupProvider defaultProvider() {
120 + return defaultProvider;
114 } 121 }
115 122
116 /** 123 /**
......