Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __INET_LDP_H
00017 #define __INET_LDP_H
00018
00019
00020 #include <string>
00021 #include <omnetpp.h>
00022 #include <iostream>
00023 #include <vector>
00024 #include "INETDefs.h"
00025 #include "LDPPacket_m.h"
00026 #include "UDPSocket.h"
00027 #include "TCPSocket.h"
00028 #include "TCPSocketMap.h"
00029 #include "IClassifier.h"
00030 #include "NotificationBoard.h"
00031
00032 #define LDP_PORT 646
00033
00034 #define LDP_TRAFFIC 4 // session (TCP) traffic
00035 #define LDP_HELLO_TRAFFIC 5 // discovery (UDP) traffic
00036 #define LDP_USER_TRAFFIC 100 // label switched user traffic
00037
00038
00039 class IInterfaceTable;
00040 class IRoutingTable;
00041 class LIBTable;
00042 class TED;
00043
00044
00048 class INET_API LDP: public cSimpleModule, public TCPSocket::CallbackInterface, public IClassifier, public INotifiable
00049 {
00050 public:
00051
00052 struct fec_t
00053 {
00054 int fecid;
00055
00056
00057 IPAddress addr;
00058 int length;
00059
00060
00061 IPAddress nextHop;
00062
00063
00064
00065 };
00066 typedef std::vector<fec_t> FecVector;
00067
00068
00069 struct fec_bind_t
00070 {
00071 int fecid;
00072
00073 IPAddress peer;
00074 int label;
00075 };
00076 typedef std::vector<fec_bind_t> FecBindVector;
00077
00078
00079 struct pending_req_t
00080 {
00081 int fecid;
00082 IPAddress peer;
00083 };
00084 typedef std::vector<pending_req_t> PendingVector;
00085
00086 struct peer_info
00087 {
00088 IPAddress peerIP;
00089 bool activeRole;
00090 TCPSocket *socket;
00091 std::string linkInterface;
00092 cMessage *timeout;
00093 };
00094 typedef std::vector<peer_info> PeerVector;
00095
00096 protected:
00097
00098 simtime_t holdTime;
00099 simtime_t helloInterval;
00100
00101
00102 FecVector fecList;
00103
00104 FecBindVector fecUp;
00105
00106 FecBindVector fecDown;
00107
00108 PendingVector pending;
00109
00110
00111 PeerVector myPeers;
00112
00113
00114
00115
00116 IInterfaceTable *ift;
00117 IRoutingTable *rt;
00118 LIBTable *lt;
00119 TED *tedmod;
00120 NotificationBoard *nb;
00121
00122 UDPSocket udpSocket;
00123 TCPSocket serverSocket;
00124 TCPSocketMap socketMap;
00125
00126
00127 cMessage *sendHelloMsg;
00128
00129 int maxFecid;
00130
00131 protected:
00135 virtual IPAddress locateNextHop(IPAddress dest);
00136
00143 virtual IPAddress findPeerAddrFromInterface(std::string interfaceName);
00144
00145
00146 std::string findInterfaceFromPeerAddr(IPAddress peerIP);
00147
00149 virtual int findPeer(IPAddress peerAddr);
00150
00152 virtual TCPSocket *getPeerSocket(IPAddress peerAddr);
00153
00155 virtual TCPSocket *findPeerSocket(IPAddress peerAddr);
00156
00157 virtual void sendToPeer(IPAddress dest, cMessage *msg);
00158
00159
00160
00161
00162 FecVector::iterator findFecEntry(FecVector& fecs, IPAddress addr, int length);
00163 FecBindVector::iterator findFecEntry(FecBindVector& fecs, int fecid, IPAddress peer);
00164
00165 virtual void sendMappingRequest(IPAddress dest, IPAddress addr, int length);
00166 virtual void sendMapping(int type, IPAddress dest, int label, IPAddress addr, int length);
00167 virtual void sendNotify(int status, IPAddress dest, IPAddress addr, int length);
00168
00169 virtual void rebuildFecList();
00170 virtual void updateFecList(IPAddress nextHop);
00171 virtual void updateFecListEntry(fec_t oldItem);
00172
00173 virtual void announceLinkChange(int tedlinkindex);
00174
00175 public:
00176 LDP();
00177 virtual ~LDP();
00178
00179 protected:
00180 virtual int numInitStages() const {return 4;}
00181 virtual void initialize(int stage);
00182 virtual void handleMessage(cMessage *msg);
00183
00184 virtual void sendHelloTo(IPAddress dest);
00185 virtual void openTCPConnectionToPeer(int peerIndex);
00186
00187 virtual void processLDPHello(LDPHello *msg);
00188 virtual void processHelloTimeout(cMessage *msg);
00189 virtual void processMessageFromTCP(cMessage *msg);
00190 virtual void processLDPPacketFromTCP(LDPPacket *ldpPacket);
00191
00192 virtual void processLABEL_MAPPING(LDPLabelMapping *packet);
00193 virtual void processLABEL_REQUEST(LDPLabelRequest *packet);
00194 virtual void processLABEL_RELEASE(LDPLabelMapping *packet);
00195 virtual void processLABEL_WITHDRAW(LDPLabelMapping *packet);
00196 virtual void processNOTIFICATION(LDPNotify* packet);
00197
00200 virtual void socketEstablished(int connId, void *yourPtr);
00201 virtual void socketDataArrived(int connId, void *yourPtr, cPacket *msg, bool urgent);
00202 virtual void socketPeerClosed(int connId, void *yourPtr);
00203 virtual void socketClosed(int connId, void *yourPtr);
00204 virtual void socketFailure(int connId, void *yourPtr, int code);
00205 virtual void socketStatusArrived(int connId, void *yourPtr, TCPStatusInfo *status) {delete status;}
00207
00208
00209 virtual bool lookupLabel(IPDatagram *ipdatagram, LabelOpVector& outLabel, std::string& outInterface, int& color);
00210
00211
00212 virtual void receiveChangeNotification(int category, const cPolymorphic *details);
00213 };
00214
00215 #endif
00216
00217