Jian Li | c4b4b58 | 2016-12-21 02:49:32 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Jian Li | c4b4b58 | 2016-12-21 02:49:32 +0900 | [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 | package org.onosproject.provider.lisp.message.impl; |
| 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.onlab.metrics.MetricsService; |
| 24 | import org.onosproject.lisp.ctl.LispController; |
| 25 | import org.onosproject.lisp.ctl.LispMessageListener; |
| 26 | import org.onosproject.lisp.ctl.LispRouterId; |
| 27 | import org.onosproject.lisp.ctl.LispRouterListener; |
| 28 | import org.onosproject.lisp.msg.protocols.LispMessage; |
| 29 | import org.onosproject.net.provider.AbstractProvider; |
| 30 | import org.onosproject.net.provider.ProviderId; |
| 31 | import org.slf4j.Logger; |
| 32 | import org.slf4j.LoggerFactory; |
| 33 | |
| 34 | /** |
| 35 | * Provider which uses an LISP controller to detect device. |
| 36 | */ |
| 37 | @Component(immediate = true) |
| 38 | public class LispMessageProvider extends AbstractProvider { |
| 39 | |
| 40 | private static final Logger log = LoggerFactory.getLogger(LispMessageProvider.class); |
| 41 | |
| 42 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 43 | protected LispController controller; |
| 44 | |
| 45 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 46 | protected MetricsService metricsService; |
| 47 | |
| 48 | private static final String SCHEME_NAME = "lisp"; |
| 49 | private static final String MESSAGE_PROVIDER_PACKAGE = |
| 50 | "org.onosproject.lisp.provider.message"; |
| 51 | |
| 52 | private final InternalDeviceProvider routerListener = new InternalDeviceProvider(); |
| 53 | |
| 54 | private final InternalControlMessageListener messageListener = |
| 55 | new InternalControlMessageListener(); |
| 56 | |
| 57 | /** |
| 58 | * Creates a LISP device provider with the supplier identifier. |
| 59 | */ |
| 60 | public LispMessageProvider() { |
| 61 | super(new ProviderId(SCHEME_NAME, MESSAGE_PROVIDER_PACKAGE)); |
| 62 | } |
| 63 | |
| 64 | @Activate |
| 65 | public void activate() { |
| 66 | |
| 67 | // listens all LISP router related events |
| 68 | controller.addRouterListener(routerListener); |
| 69 | |
| 70 | // listens all LISP control messages |
| 71 | controller.addMessageListener(messageListener); |
| 72 | |
| 73 | attachRouters(); |
| 74 | |
| 75 | log.info("Started"); |
| 76 | } |
| 77 | |
| 78 | @Deactivate |
| 79 | public void deactivate() { |
| 80 | |
| 81 | detachRouters(); |
| 82 | |
| 83 | // stops listening all LISP router related events |
| 84 | controller.removeRouterListener(routerListener); |
| 85 | |
| 86 | // stops listening all LISP control messages |
| 87 | controller.removeMessageListener(messageListener); |
| 88 | |
| 89 | log.info("Stopped"); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Attaches all discovered LISP router to listen the router events. |
| 94 | */ |
| 95 | private void attachRouters() { |
| 96 | |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Detaches all LISP routers from listener. |
| 101 | */ |
| 102 | private void detachRouters() { |
| 103 | |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * A routerListener for LISP router agent. |
| 108 | */ |
| 109 | private class InternalDeviceProvider implements LispRouterListener { |
| 110 | |
| 111 | @Override |
| 112 | public void routerAdded(LispRouterId routerId) { |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public void routerRemoved(LispRouterId routerId) { |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public void routerChanged(LispRouterId routerId) { |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * A routerListener for all LISP control messages. |
| 126 | */ |
| 127 | private class InternalControlMessageListener implements LispMessageListener { |
| 128 | |
| 129 | @Override |
| 130 | public void handleIncomingMessage(LispRouterId routerId, LispMessage msg) { |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public void handleOutgoingMessage(LispRouterId routerId, LispMessage msg) { |
| 135 | } |
| 136 | } |
| 137 | } |