Sithara Punnassery | 43833e1 | 2017-03-14 16:29:19 -0700 | [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 | |
| 17 | package org.onosproject.netconf.storeadapter; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | |
| 23 | import org.apache.felix.scr.annotations.Deactivate; |
| 24 | import org.apache.felix.scr.annotations.Reference; |
| 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 26 | import org.onosproject.config.DynamicConfigEvent; |
| 27 | import org.onosproject.config.DynamicConfigListener; |
| 28 | import org.onosproject.config.DynamicConfigService; |
| 29 | import org.onosproject.config.Filter; |
| 30 | import org.onosproject.yang.model.DataNode; |
| 31 | import org.onosproject.yang.model.ResourceId; |
| 32 | import org.slf4j.Logger; |
| 33 | import org.slf4j.LoggerFactory; |
| 34 | |
| 35 | @Beta |
| 36 | @Component(immediate = true) |
| 37 | public class NetConfListener implements DynamicConfigListener { |
| 38 | |
| 39 | private static final Logger log = LoggerFactory.getLogger(NetConfListener.class); |
| 40 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 41 | protected DynamicConfigService cfgServcie; |
| 42 | public static final String DEVNMSPACE = "namespace1"; |
| 43 | |
| 44 | private ResourceId resId = new ResourceId.Builder() |
| 45 | .addBranchPointSchema("device", DEVNMSPACE ) |
| 46 | .build(); |
| 47 | @Activate |
| 48 | protected void activate() { |
| 49 | cfgServcie.addListener(this); |
| 50 | log.info("NetConfListener Started"); |
| 51 | } |
| 52 | |
| 53 | @Deactivate |
| 54 | protected void deactivate() { |
| 55 | cfgServcie.removeListener(this); |
| 56 | log.info("NetConfListener Stopped"); |
| 57 | } |
| 58 | |
| 59 | public boolean isRelevant(DynamicConfigEvent event) { |
| 60 | if (event.subject().equals(resId)) { |
| 61 | log.info("isRelevant {} = {}", resId, event.subject()); |
| 62 | return true; |
| 63 | } else { |
| 64 | log.info("isRelevant {} != {}", resId, event.subject()); |
| 65 | return false; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | public void event(DynamicConfigEvent event) { |
| 70 | if (!isRelevant(event)) { |
| 71 | log.info("event is not relevanyt!!!! {} != {}", resId, event.subject()); |
| 72 | return; |
| 73 | } |
| 74 | switch (event.type()) { |
| 75 | case NODE_ADDED: |
| 76 | log.info("NetConfListener: RXD NODE_ADDED event"); |
| 77 | Filter filt = new Filter(); |
| 78 | DataNode node = cfgServcie.readNode(event.subject(), filt); |
| 79 | //call netconf passive |
| 80 | break; |
| 81 | case NODE_UPDATED: |
| 82 | log.info("NetConfListener: RXD NODE_UPDATED event"); |
| 83 | break; |
| 84 | case NODE_REPLACED: |
| 85 | log.info("NetConfListener: RXD NODE_REPLACED event"); |
| 86 | break; |
| 87 | case NODE_DELETED: |
| 88 | log.info("NetConfListener: RXD NODE_DELETED event"); |
| 89 | break; |
| 90 | case UNKNOWN_OPRN: |
| 91 | default: |
| 92 | log.warn("NetConfListener: unknown event: {}", event.type()); |
| 93 | break; |
| 94 | } |
| 95 | } |
| 96 | } |