00001 /* 00002 * Copyright 2004-2006 Intel Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef _LINKSTATE_ROUTER_H_ 00018 #define _LINKSTATE_ROUTER_H_ 00019 00020 #include "bundling/BundleEventHandler.h" 00021 #include "BundleRouter.h" 00022 #include "LinkStateGraph.h" 00023 #include "reg/Registration.h" 00024 #include <set> 00025 00026 namespace dtn { 00027 00028 class LinkStateRouter : public BundleRouter { 00029 public: 00030 typedef enum { 00031 LS_ANNOUNCEMENT // Link state announcement 00032 } ls_type; 00033 00034 /* 00035 * These link state announcements aren't exactly elegant. However, it makes for 00036 * simple code. Optimization will be needed at some point. 00037 */ 00038 struct LinkStateAnnouncement { 00039 static const u_int8_t LINK_DOWN = 255; 00040 00041 ls_type type; 00042 char from[MAX_EID]; 00043 char to[MAX_EID]; 00044 u_int8_t cost; 00045 } __attribute__((packed)); 00046 00047 LinkStateRouter(); 00048 00049 void handle_event(BundleEvent* event) 00050 { 00051 dispatch_event(event); 00052 } 00053 00054 void handle_contact_down(ContactDownEvent* event); 00055 void handle_contact_up(ContactUpEvent* event); 00056 LinkStateGraph* graph() { return &graph_; } 00057 00058 void initialize(); 00059 void get_routing_state(oasys::StringBuffer* buf); 00060 00061 protected: 00062 LinkStateGraph graph_; 00063 00064 /* 00065 * Send link-state announcement to all neighbors. 00066 * 00067 * exists - true if this announcement is about an existing link\ 00068 * edge - the edge we're announcing 00069 */ 00070 void flood_announcement(LinkStateGraph::Edge* edge, bool exists); 00071 00072 /* 00073 * Send link-state announcement to one neighbor. Used for transferring 00074 * the entire routing database. 00075 * 00076 * exists - the current state of the edge 00077 * outgoing_link - the link through which to send the announcement 00078 * edge - the edge that the announcement is all about 00079 */ 00080 void send_announcement(LinkStateGraph::Edge* edge, Link* outgoing_link, bool exists); 00081 00082 void handle_bundle_received(BundleReceivedEvent* event); 00083 00084 00085 class LSRegistration : public Registration { 00086 public: 00087 LSRegistration(LinkStateRouter* router); 00088 00089 LinkStateRouter* router_; 00090 00094 void deliver_bundle(Bundle* bundle); 00095 00096 }; 00097 00098 LSRegistration* reg_; 00099 00100 }; 00101 00102 } // namespace dtn 00103 00104 #endif /* _LINKSTATE_ROUTER_H_ */