Gaurav Agrawal | c6d536f | 2017-03-17 11:56:31 +0530 | [diff] [blame] | 1 | /* |
| 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 | */ |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame^] | 16 | |
| 17 | package org.onosproject.l3vpn.netl3vpn.impl; |
Gaurav Agrawal | c6d536f | 2017-03-17 11:56:31 +0530 | [diff] [blame] | 18 | |
| 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 24 | import org.onosproject.core.CoreService; |
| 25 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev20130715.IetfInetTypes; |
| 26 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.l3vpn.svc.rev20160730.IetfL3VpnSvc; |
| 27 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20130715.IetfYangTypes; |
| 28 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.l3vpn.svc.ext.rev20160730.L3VpnSvcExt; |
| 29 | import org.onosproject.yang.model.YangModel; |
| 30 | import org.onosproject.yang.model.YangModuleId; |
| 31 | import org.onosproject.yang.runtime.DefaultAppModuleInfo; |
| 32 | import org.onosproject.yang.runtime.DefaultModelRegistrationParam; |
| 33 | import org.onosproject.yang.runtime.ModelRegistrationParam; |
| 34 | import org.onosproject.yang.runtime.YangModelRegistry; |
| 35 | import org.slf4j.Logger; |
| 36 | import org.slf4j.LoggerFactory; |
| 37 | |
| 38 | import java.util.Iterator; |
| 39 | |
| 40 | import static org.onosproject.yang.runtime.helperutils.YangApacheUtils.getYangModel; |
| 41 | |
| 42 | /** |
| 43 | * The IETF net l3vpn manager implementation. |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame^] | 44 | * // TODO: Implementation of the manager class. |
Gaurav Agrawal | c6d536f | 2017-03-17 11:56:31 +0530 | [diff] [blame] | 45 | */ |
| 46 | @Component(immediate = true) |
| 47 | public class NetL3vpnManager { |
| 48 | |
| 49 | private static final String APP_ID = "org.onosproject.app.l3vpn"; |
| 50 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 51 | |
| 52 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 53 | protected CoreService coreService; |
| 54 | |
| 55 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 56 | protected YangModelRegistry modelRegistry; |
| 57 | |
| 58 | private ModelRegistrationParam regParam = null; |
| 59 | |
| 60 | @Activate |
| 61 | protected void activate() { |
| 62 | coreService.registerApplication(APP_ID); |
| 63 | log.info("Started"); |
| 64 | //TODO implementation |
| 65 | } |
| 66 | |
| 67 | @Deactivate |
| 68 | protected void deactivate() { |
| 69 | modelRegistry.unregisterModel(regParam); |
| 70 | log.info("Stopped"); |
| 71 | } |
| 72 | |
| 73 | private void registerModel() { |
| 74 | YangModel model = getYangModel(getClass()); |
| 75 | Iterator<YangModuleId> it = model.getYangModulesId().iterator(); |
| 76 | |
| 77 | //Create model registration param. |
| 78 | ModelRegistrationParam.Builder b = |
| 79 | DefaultModelRegistrationParam.builder().setYangModel(model); |
| 80 | |
| 81 | YangModuleId id; |
| 82 | while (it.hasNext()) { |
| 83 | id = it.next(); |
| 84 | switch (id.moduleName()) { |
| 85 | case "ietf-inet-types": |
| 86 | b.addAppModuleInfo(id, new DefaultAppModuleInfo( |
| 87 | IetfInetTypes.class, null)); |
| 88 | break; |
| 89 | case "ietf-l3vpn-svc": |
| 90 | b.addAppModuleInfo(id, new DefaultAppModuleInfo( |
| 91 | IetfL3VpnSvc.class, null)); |
| 92 | break; |
| 93 | case "ietf-yang-types": |
| 94 | b.addAppModuleInfo(id, new DefaultAppModuleInfo( |
| 95 | IetfYangTypes.class, null)); |
| 96 | break; |
| 97 | case "l3vpn-svc-ext": |
| 98 | b.addAppModuleInfo(id, new DefaultAppModuleInfo( |
| 99 | L3VpnSvcExt.class, null)); |
| 100 | break; |
| 101 | default: |
| 102 | break; |
| 103 | } |
| 104 | } |
| 105 | regParam = b.build(); |
| 106 | modelRegistry.registerModel(regParam); |
| 107 | } |
| 108 | } |