Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 1 | package org.onlab.onos.sdnip; |
| 2 | |
| 3 | import static org.slf4j.LoggerFactory.getLogger; |
| 4 | |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame^] | 5 | import java.util.Collection; |
| 6 | |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 7 | import org.apache.felix.scr.annotations.Activate; |
| 8 | import org.apache.felix.scr.annotations.Component; |
| 9 | import org.apache.felix.scr.annotations.Deactivate; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 10 | import org.apache.felix.scr.annotations.Reference; |
| 11 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame^] | 12 | import org.apache.felix.scr.annotations.Service; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 13 | import org.onlab.onos.net.host.HostService; |
| 14 | import org.onlab.onos.net.intent.IntentService; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 15 | import org.onlab.onos.sdnip.RouteUpdate.Type; |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame^] | 16 | import org.onlab.onos.sdnip.bgp.BgpRouteEntry; |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 17 | import org.onlab.onos.sdnip.bgp.BgpSessionManager; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 18 | import org.onlab.onos.sdnip.config.SdnIpConfigReader; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.IpPrefix; |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 21 | import org.slf4j.Logger; |
| 22 | |
| 23 | /** |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame^] | 24 | * Component for the SDN-IP peering application. |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 25 | */ |
| 26 | @Component(immediate = true) |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame^] | 27 | @Service |
| 28 | public class SdnIp implements SdnIpService { |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 29 | |
| 30 | private final Logger log = getLogger(getClass()); |
| 31 | |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 32 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 33 | protected IntentService intentService; |
| 34 | |
| 35 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 36 | protected HostService hostService; |
| 37 | |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 38 | private SdnIpConfigReader config; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 39 | private PeerConnectivity peerConnectivity; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 40 | private Router router; |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 41 | private BgpSessionManager bgpSessionManager; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 42 | |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 43 | @Activate |
| 44 | protected void activate() { |
| 45 | log.debug("SDN-IP started"); |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 46 | |
| 47 | config = new SdnIpConfigReader(); |
| 48 | config.init(); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 49 | |
| 50 | InterfaceService interfaceService = new HostServiceBasedInterfaceService(hostService); |
| 51 | |
| 52 | peerConnectivity = new PeerConnectivity(config, interfaceService, intentService); |
| 53 | peerConnectivity.start(); |
| 54 | |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 55 | router = new Router(intentService, hostService, config, interfaceService); |
| 56 | router.start(); |
| 57 | |
Jonathan Hart | ab63aac | 2014-10-16 08:52:55 -0700 | [diff] [blame] | 58 | bgpSessionManager = new BgpSessionManager(router); |
| 59 | bgpSessionManager.startUp(2000); // TODO |
| 60 | |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 61 | // TODO need to disable link discovery on external ports |
| 62 | |
| 63 | router.update(new RouteUpdate(Type.UPDATE, new RouteEntry( |
| 64 | IpPrefix.valueOf("172.16.20.0/24"), |
| 65 | IpAddress.valueOf("192.168.10.1")))); |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Deactivate |
| 69 | protected void deactivate() { |
| 70 | log.info("Stopped"); |
| 71 | } |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame^] | 72 | |
| 73 | @Override |
| 74 | public Collection<BgpRouteEntry> getBgpRoutes() { |
| 75 | return bgpSessionManager.getBgpRoutes(); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public Collection<RouteEntry> getRoutes() { |
| 80 | return router.getRoutes(); |
| 81 | } |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 82 | } |