blob: d0a5c221ba0da72553a494c199af269fc0f309c8 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska781d18b2014-10-27 10:31:25 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.sdnip;
Jonathan Hart039d2b12014-10-10 09:33:04 -070017
Jonathan Hart039d2b12014-10-10 09:33:04 -070018import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Deactivate;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070021import org.apache.felix.scr.annotations.Reference;
22import org.apache.felix.scr.annotations.ReferenceCardinality;
Pingping Linc07781f2015-10-30 00:44:41 -070023import org.onosproject.app.ApplicationService;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.core.ApplicationId;
25import org.onosproject.core.CoreService;
Jonathan Hart4cb39882015-08-12 23:50:55 -040026import org.onosproject.incubator.net.intf.InterfaceService;
Pingping Linc07781f2015-10-30 00:44:41 -070027import org.onosproject.net.config.NetworkConfigService;
Jonathan Hart365335e2015-12-10 11:09:53 -080028import org.onosproject.routing.IntentSynchronizationAdminService;
Jonathan Hart9a426f82015-09-03 15:43:13 +020029import org.onosproject.routing.IntentSynchronizationService;
Jonathan Hart2da1e602015-02-18 19:09:24 -080030import org.onosproject.routing.RoutingService;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080031import org.slf4j.Logger;
Pavlin Radoslavov8b752442014-11-18 14:34:37 -080032
Jonathan Hart365335e2015-12-10 11:09:53 -080033import static org.slf4j.LoggerFactory.getLogger;
34
Jonathan Hart039d2b12014-10-10 09:33:04 -070035/**
Jonathan Hart0b04bed2014-10-16 16:39:19 -070036 * Component for the SDN-IP peering application.
Jonathan Hart039d2b12014-10-10 09:33:04 -070037 */
38@Component(immediate = true)
Jonathan Hart365335e2015-12-10 11:09:53 -080039public class SdnIp {
Jonathan Hart039d2b12014-10-10 09:33:04 -070040
Jonathan Hart365335e2015-12-10 11:09:53 -080041 public static final String SDN_IP_APP = "org.onosproject.sdnip";
Jonathan Hart039d2b12014-10-10 09:33:04 -070042 private final Logger log = getLogger(getClass());
43
Jonathan Hartdc711bd2014-10-15 11:24:23 -070044 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Thomas Vachuskab97cf282014-10-20 23:31:12 -070045 protected CoreService coreService;
46
47 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pingping Linc07781f2015-10-30 00:44:41 -070048 protected ApplicationService applicationService;
49
50 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pavlin Radoslavov492cc3a2015-01-22 18:46:26 -080051 protected NetworkConfigService networkConfigService;
52
Jonathan Hart4cb39882015-08-12 23:50:55 -040053 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
54 protected InterfaceService interfaceService;
55
Jonathan Hart365335e2015-12-10 11:09:53 -080056 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
57 protected IntentSynchronizationService intentSynchronizer;
Jonathan Hart41349e92015-02-09 14:14:02 -080058
Jonathan Hart365335e2015-12-10 11:09:53 -080059 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 protected IntentSynchronizationAdminService intentSynchronizerAdmin;
61
62 private PeerConnectivityManager peerConnectivity;
63
Pavlin Radoslavovc91eebe2014-11-25 18:45:46 -080064 private ApplicationId appId;
Pavlin Radoslavov8b752442014-11-18 14:34:37 -080065
Jonathan Hart039d2b12014-10-10 09:33:04 -070066 @Activate
Jonathan Hartd24fafb2015-02-09 17:55:32 -080067 protected void activate() {
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080068 appId = coreService.registerApplication(SDN_IP_APP);
Jonathan Hartdc711bd2014-10-15 11:24:23 -070069
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080070 peerConnectivity = new PeerConnectivityManager(appId,
71 intentSynchronizer,
Jonathan Hart4cb39882015-08-12 23:50:55 -040072 networkConfigService,
Jonathan Hart365335e2015-12-10 11:09:53 -080073 coreService.registerApplication(RoutingService.ROUTER_APP_ID),
Jonathan Hart4cb39882015-08-12 23:50:55 -040074 interfaceService);
Jonathan Hartdc711bd2014-10-15 11:24:23 -070075 peerConnectivity.start();
76
Jonathan Hart365335e2015-12-10 11:09:53 -080077 // TODO fix removing intents
Pingping Linc07781f2015-10-30 00:44:41 -070078 applicationService.registerDeactivateHook(appId,
Jonathan Hart365335e2015-12-10 11:09:53 -080079 intentSynchronizerAdmin::removeIntents);
Pingping Linc07781f2015-10-30 00:44:41 -070080
Jonathan Hart365335e2015-12-10 11:09:53 -080081 log.info("SDN-IP started");
Jonathan Hart039d2b12014-10-10 09:33:04 -070082 }
83
84 @Deactivate
85 protected void deactivate() {
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080086 peerConnectivity.stop();
Pavlin Radoslavov8b752442014-11-18 14:34:37 -080087
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080088 log.info("SDN-IP Stopped");
Jonathan Hart039d2b12014-10-10 09:33:04 -070089 }
Jonathan Hart0b04bed2014-10-16 16:39:19 -070090
Jonathan Hart51372182014-12-03 21:32:34 -080091 /**
92 * Converts DPIDs of the form xx:xx:xx:xx:xx:xx:xx to OpenFlow provider
93 * device URIs.
94 *
95 * @param dpid the DPID string to convert
96 * @return the URI string for this device
97 */
Jonathan Hartce430a42014-10-16 20:44:29 -070098 static String dpidToUri(String dpid) {
99 return "of:" + dpid.replace(":", "");
100 }
Pavlin Radoslavov8b752442014-11-18 14:34:37 -0800101
Pavlin Radoslavov8b752442014-11-18 14:34:37 -0800102
Jonathan Hart039d2b12014-10-10 09:33:04 -0700103}