Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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.bgp.controller.impl; |
| 18 | |
| 19 | import static org.onlab.util.Tools.groupedThreads; |
| 20 | import java.util.concurrent.ExecutorService; |
| 21 | import java.util.concurrent.Executors; |
| 22 | import org.apache.felix.scr.annotations.Activate; |
| 23 | import org.apache.felix.scr.annotations.Component; |
| 24 | import org.apache.felix.scr.annotations.Deactivate; |
| 25 | import org.apache.felix.scr.annotations.Service; |
| 26 | import org.onosproject.bgp.controller.BGPCfg; |
| 27 | import org.onosproject.bgp.controller.BGPController; |
| 28 | import org.onosproject.bgp.controller.BGPId; |
| 29 | import org.onosproject.bgpio.protocol.BGPMessage; |
| 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
| 32 | |
| 33 | @Component(immediate = true) |
| 34 | @Service |
| 35 | public class BGPControllerImpl implements BGPController { |
| 36 | |
| 37 | private static final Logger log = LoggerFactory.getLogger(BGPControllerImpl.class); |
| 38 | |
| 39 | private final ExecutorService executorMsgs = Executors.newFixedThreadPool(32, |
| 40 | groupedThreads("onos/bgp", |
| 41 | "event-stats-%d")); |
| 42 | |
| 43 | private final ExecutorService executorBarrier = Executors.newFixedThreadPool(4, |
| 44 | groupedThreads("onos/bgp", |
| 45 | "event-barrier-%d")); |
| 46 | |
| 47 | final Controller ctrl = new Controller(this); |
| 48 | |
| 49 | private BGPConfig bgpconfig = new BGPConfig(); |
| 50 | |
| 51 | @Activate |
| 52 | public void activate() { |
| 53 | this.ctrl.start(); |
| 54 | log.info("Started"); |
| 55 | } |
| 56 | |
| 57 | @Deactivate |
| 58 | public void deactivate() { |
| 59 | // Close all connected peers |
| 60 | this.ctrl.stop(); |
| 61 | log.info("Stopped"); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public void writeMsg(BGPId bgpId, BGPMessage msg) { |
| 66 | // TODO: Send message |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public void processBGPPacket(BGPId bgpId, BGPMessage msg) { |
| 71 | |
| 72 | switch (msg.getType()) { |
| 73 | case OPEN: |
| 74 | // TODO: Process Open message |
| 75 | break; |
| 76 | case KEEP_ALIVE: |
| 77 | // TODO: Process keepalive message |
| 78 | break; |
| 79 | case NOTIFICATION: |
| 80 | // TODO: Process notificatoin message |
| 81 | break; |
| 82 | case UPDATE: |
| 83 | // TODO: Process update message |
| 84 | break; |
| 85 | default: |
| 86 | // TODO: Process other message |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Get controller instance. |
| 93 | * |
| 94 | * @return ctrl the controller. |
| 95 | */ |
| 96 | public Controller getController() { |
| 97 | return ctrl; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public BGPCfg getConfig() { |
| 102 | return this.bgpconfig; |
| 103 | } |
| 104 | } |