Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 16 | package org.onlab.onos.sdnip; |
| 17 | |
| 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame] | 20 | import java.util.Collection; |
| 21 | |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 22 | import org.apache.felix.scr.annotations.Activate; |
| 23 | import org.apache.felix.scr.annotations.Component; |
| 24 | import org.apache.felix.scr.annotations.Deactivate; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 25 | import org.apache.felix.scr.annotations.Reference; |
| 26 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame] | 27 | import org.apache.felix.scr.annotations.Service; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 28 | import org.onlab.onos.core.ApplicationId; |
| 29 | import org.onlab.onos.core.CoreService; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 30 | import org.onlab.onos.net.host.HostService; |
| 31 | import org.onlab.onos.net.intent.IntentService; |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame] | 32 | import org.onlab.onos.sdnip.bgp.BgpRouteEntry; |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 33 | import org.onlab.onos.sdnip.bgp.BgpSessionManager; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 34 | import org.onlab.onos.sdnip.config.SdnIpConfigReader; |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 35 | import org.slf4j.Logger; |
| 36 | |
| 37 | /** |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame] | 38 | * Component for the SDN-IP peering application. |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 39 | */ |
| 40 | @Component(immediate = true) |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame] | 41 | @Service |
| 42 | public class SdnIp implements SdnIpService { |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 43 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 44 | private static final String SDN_IP_APP = "org.onlab.onos.sdnip"; |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 45 | |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 46 | private final Logger log = getLogger(getClass()); |
| 47 | |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 48 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 49 | protected CoreService coreService; |
| 50 | |
| 51 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 52 | protected IntentService intentService; |
| 53 | |
| 54 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 55 | protected HostService hostService; |
| 56 | |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 57 | private SdnIpConfigReader config; |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 58 | private PeerConnectivityManager peerConnectivity; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 59 | private Router router; |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 60 | private BgpSessionManager bgpSessionManager; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 61 | |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 62 | @Activate |
| 63 | protected void activate() { |
| 64 | log.debug("SDN-IP started"); |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 65 | |
| 66 | config = new SdnIpConfigReader(); |
| 67 | config.init(); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 68 | |
Jonathan Hart | ce37f6d | 2014-10-20 10:25:03 -0700 | [diff] [blame] | 69 | InterfaceService interfaceService = new HostToInterfaceAdaptor(hostService); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 70 | |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 71 | ApplicationId appId = coreService.registerApplication(SDN_IP_APP); |
| 72 | |
| 73 | peerConnectivity = new PeerConnectivityManager(appId, config, |
| 74 | interfaceService, intentService); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 75 | peerConnectivity.start(); |
| 76 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 77 | router = new Router(appId, intentService, hostService, config, interfaceService); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 78 | router.start(); |
| 79 | |
Jonathan Hart | ec2df01 | 2014-10-23 16:40:24 -0700 | [diff] [blame] | 80 | // Manually set the router as the leader to allow testing |
| 81 | // TODO change this when we get a leader election |
| 82 | router.leaderChanged(true); |
| 83 | |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 84 | bgpSessionManager = new BgpSessionManager(router); |
| 85 | bgpSessionManager.startUp(2000); // TODO |
| 86 | |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 87 | // TODO need to disable link discovery on external ports |
Jonathan Hart | 4c2b15e | 2014-10-20 13:10:56 -0700 | [diff] [blame] | 88 | |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | @Deactivate |
| 92 | protected void deactivate() { |
| 93 | log.info("Stopped"); |
| 94 | } |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame] | 95 | |
| 96 | @Override |
| 97 | public Collection<BgpRouteEntry> getBgpRoutes() { |
| 98 | return bgpSessionManager.getBgpRoutes(); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public Collection<RouteEntry> getRoutes() { |
| 103 | return router.getRoutes(); |
| 104 | } |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 105 | |
Jonathan Hart | ec2df01 | 2014-10-23 16:40:24 -0700 | [diff] [blame] | 106 | @Override |
| 107 | public void modifyPrimary(boolean isPrimary) { |
| 108 | router.leaderChanged(isPrimary); |
| 109 | } |
| 110 | |
Jonathan Hart | ce430a4 | 2014-10-16 20:44:29 -0700 | [diff] [blame] | 111 | static String dpidToUri(String dpid) { |
| 112 | return "of:" + dpid.replace(":", ""); |
| 113 | } |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 114 | } |