yoonseon | 1021932 | 2017-01-18 16:54:12 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
yoonseon | 1021932 | 2017-01-18 16:54:12 -0800 | [diff] [blame] | 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.incubator.net.virtual.impl.provider; |
| 18 | |
yoonseon | 1021932 | 2017-01-18 16:54:12 -0800 | [diff] [blame] | 19 | import org.onosproject.incubator.net.virtual.NetworkId; |
| 20 | import org.onosproject.incubator.net.virtual.provider.AbstractVirtualProvider; |
| 21 | import org.onosproject.incubator.net.virtual.provider.VirtualGroupProvider; |
| 22 | import org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.group.GroupEvent; |
| 25 | import org.onosproject.net.group.GroupListener; |
| 26 | import org.onosproject.net.group.GroupOperation; |
| 27 | import org.onosproject.net.group.GroupOperations; |
| 28 | import org.onosproject.net.group.GroupService; |
| 29 | import org.onosproject.net.provider.ProviderId; |
| 30 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 31 | import org.osgi.service.component.annotations.Activate; |
| 32 | import org.osgi.service.component.annotations.Component; |
| 33 | import org.osgi.service.component.annotations.Deactivate; |
| 34 | import org.osgi.service.component.annotations.Modified; |
| 35 | import org.osgi.service.component.annotations.Reference; |
| 36 | import org.osgi.service.component.annotations.ReferenceCardinality; |
yoonseon | 1021932 | 2017-01-18 16:54:12 -0800 | [diff] [blame] | 37 | import org.slf4j.Logger; |
| 38 | |
| 39 | import static org.slf4j.LoggerFactory.getLogger; |
| 40 | |
| 41 | /** |
| 42 | * Provider to handle Group for virtual network. |
| 43 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 44 | @Component(service = VirtualGroupProvider.class) |
yoonseon | 1021932 | 2017-01-18 16:54:12 -0800 | [diff] [blame] | 45 | public class DefaultVirtualGroupProvider extends AbstractVirtualProvider |
| 46 | implements VirtualGroupProvider { |
| 47 | |
| 48 | private final Logger log = getLogger(getClass()); |
| 49 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 50 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
yoonseon | 1021932 | 2017-01-18 16:54:12 -0800 | [diff] [blame] | 51 | protected VirtualProviderRegistryService providerRegistryService; |
| 52 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 53 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
yoonseon | 1021932 | 2017-01-18 16:54:12 -0800 | [diff] [blame] | 54 | 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 | } |