blob: 93834752d54c1d4a815f05e4e81301d7d5b6b1e9 [file] [log] [blame]
yoonseon10219322017-01-18 16:54:12 -08001/*
2 * Copyright 2017-present 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.incubator.net.virtual.impl.provider;
18
19import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Modified;
23import org.apache.felix.scr.annotations.Reference;
24import org.apache.felix.scr.annotations.ReferenceCardinality;
25import org.apache.felix.scr.annotations.Service;
26import org.onosproject.incubator.net.virtual.NetworkId;
27import org.onosproject.incubator.net.virtual.provider.AbstractVirtualProvider;
28import org.onosproject.incubator.net.virtual.provider.VirtualGroupProvider;
29import org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService;
30import org.onosproject.net.DeviceId;
31import org.onosproject.net.group.GroupEvent;
32import org.onosproject.net.group.GroupListener;
33import org.onosproject.net.group.GroupOperation;
34import org.onosproject.net.group.GroupOperations;
35import org.onosproject.net.group.GroupService;
36import org.onosproject.net.provider.ProviderId;
37import org.osgi.service.component.ComponentContext;
38import org.slf4j.Logger;
39
40import static org.slf4j.LoggerFactory.getLogger;
41
42/**
43 * Provider to handle Group for virtual network.
44 */
45@Component(immediate = true)
46@Service
47public class DefaultVirtualGroupProvider extends AbstractVirtualProvider
48 implements VirtualGroupProvider {
49
50 private final Logger log = getLogger(getClass());
51
52 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
53 protected VirtualProviderRegistryService providerRegistryService;
54
55 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
56 protected GroupService groupService;
57
58 private InternalGroupEventListener internalGroupEventListener;
59
60 /**
61 * Creates a virtual provider with the supplied identifier.
62 */
63 public DefaultVirtualGroupProvider() {
64 super(new ProviderId("vnet-group", "org.onosproject.virtual.of-group"));
65 }
66
67 @Activate
68 public void activate() {
69 providerRegistryService.registerProvider(this);
70
71 internalGroupEventListener = new InternalGroupEventListener();
72 groupService.addListener(internalGroupEventListener);
73
74 log.info("Started");
75 }
76
77 @Deactivate
78 public void deactivate() {
79 groupService.removeListener(internalGroupEventListener);
80 providerRegistryService.unregisterProvider(this);
81 }
82
83 @Modified
84 protected void modified(ComponentContext context) {
85 }
86
87 @Override
88 public void performGroupOperation(NetworkId networkId, DeviceId deviceId, GroupOperations groupOps) {
89 for (GroupOperation groupOperation: groupOps.operations()) {
90 switch (groupOperation.opType()) {
91 case ADD:
92 //TODO: devirtualize + groupAdd
93 log.info("Group Add is not supported, yet");
94 break;
95 case MODIFY:
96 //TODO: devirtualize + groupMod
97 log.info("Group Modify is not supported, yet");
98 break;
99 case DELETE:
100 //TODO: devirtualize + groupDel
101 log.info("Group Delete is not supported, yet");
102 break;
103 default:
104 log.error("Unsupported Group operation");
105 return;
106 }
107 }
108 }
109
110 private class InternalGroupEventListener implements GroupListener {
111 @Override
112 public void event(GroupEvent event) {
113 switch (event.type()) {
114 //TODO: virtualize + notify to virtual provider service
115 case GROUP_ADD_REQUESTED:
116 case GROUP_UPDATE_REQUESTED:
117 case GROUP_REMOVE_REQUESTED:
118 case GROUP_ADDED:
119 case GROUP_UPDATED:
120 case GROUP_REMOVED:
121 case GROUP_ADD_FAILED:
122 case GROUP_UPDATE_FAILED:
123 case GROUP_REMOVE_FAILED:
124 case GROUP_BUCKET_FAILOVER:
125 default:
126 break;
127 }
128 }
129 }
130}