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