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