LDP.h

Go to the documentation of this file.
00001 //
00002 // (C) 2005 Vojtech Janota
00003 // (C) 2004 Andras Varga
00004 //
00005 // This library is free software, you can redistribute it
00006 // and/or modify
00007 // it under  the terms of the GNU Lesser General Public License
00008 // as published by the Free Software Foundation;
00009 // either version 2 of the License, or any later version.
00010 // The library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00013 // See the GNU Lesser General Public License for more details.
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         // FEC value
00057         IPAddress addr;
00058         int length;
00059 
00060         // FEC's next hop address
00061         IPAddress nextHop;
00062 
00063         // possibly also: (speed up)
00064         // std::string nextHopInterface
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;   // IP address of LDP peer
00089         bool activeRole;    // we're in active or passive role in this session
00090         TCPSocket *socket;  // TCP socket
00091         std::string linkInterface;
00092         cMessage *timeout;
00093     };
00094     typedef std::vector<peer_info> PeerVector;
00095 
00096   protected:
00097     // configuration
00098     simtime_t holdTime;
00099     simtime_t helloInterval;
00100 
00101     // currently recognized FECs
00102     FecVector fecList;
00103     // bindings advertised upstream
00104     FecBindVector fecUp;
00105     // mappings learnt from downstream
00106     FecBindVector fecDown;
00107     // currently requested and yet unserviced mappings
00108     PendingVector pending;
00109 
00110     // the collection of all HELLO adjacencies.
00111     PeerVector myPeers;
00112 
00113     //
00114     // other variables:
00115     //
00116     IInterfaceTable *ift;
00117     IRoutingTable *rt;
00118     LIBTable *lt;
00119     TED *tedmod;
00120     NotificationBoard *nb;
00121 
00122     UDPSocket udpSocket;     // for sending/receiving Hello
00123     TCPSocket serverSocket;  // for listening on LDP_PORT
00124     TCPSocketMap socketMap;  // holds TCP connections with peers
00125 
00126     // hello timeout message
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     //This method is the reserve of above method
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     //bool matches(const FEC_TLV& a, const FEC_TLV& b);
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     // IClassifier
00209     virtual bool lookupLabel(IPDatagram *ipdatagram, LabelOpVector& outLabel, std::string& outInterface, int& color);
00210 
00211     // INotifiable
00212     virtual void receiveChangeNotification(int category, const cPolymorphic *details);
00213 };
00214 
00215 #endif
00216 
00217