OLD | NEW |
(Empty) | |
| 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2009 University of Pennsylvania |
| 4 * |
| 5 * This program is free software; you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 2 as |
| 7 * published by the Free Software Foundation; |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software |
| 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 */ |
| 18 |
| 19 #ifndef DHASH_IPV4_H |
| 20 #define DHASH_IPV4_H |
| 21 |
| 22 #include "ns3/application.h" |
| 23 #include "ns3/event-id.h" |
| 24 #include "ns3/ptr.h" |
| 25 #include "ns3/ipv4-address.h" |
| 26 #include "ns3/traced-callback.h" |
| 27 #include "ns3/timer.h" |
| 28 #include "ns3/simulator.h" |
| 29 #include "ns3/socket.h" |
| 30 #include "ns3/inet-socket-address.h" |
| 31 #include "ns3/callback.h" |
| 32 #include "chord-identifier.h" |
| 33 #include "dhash-message.h" |
| 34 #include "dhash-object.h" |
| 35 #include "dhash-connection.h" |
| 36 #include "dhash-transaction.h" |
| 37 #include <map> |
| 38 #include <vector> |
| 39 |
| 40 /* Static defines */ |
| 41 #define DEFAULT_CONNECTION_INACTIVITY_TIMEOUT 10000 |
| 42 #define DEFAULT_AUDIT_OBJECTS_TIMEOUT 600000 |
| 43 |
| 44 namespace ns3 { |
| 45 |
| 46 class Socket; |
| 47 class Packet; |
| 48 class ChordIpv4; |
| 49 |
| 50 /** |
| 51 * \ingroup chordipv4 |
| 52 * \class DHashIpv4 |
| 53 * \brief DHash over Chord·· |
| 54 */ |
| 55 class DHashIpv4 : public Object· |
| 56 { |
| 57 |
| 58 public: |
| 59 DHashIpv4 (); |
| 60 virtual ~DHashIpv4 (); |
| 61 void DoDispose (void); |
| 62 /** |
| 63 * \brief Start DHash layer |
| 64 */ |
| 65 void Start (Ptr<ChordIpv4> chordIpv4); |
| 66 static TypeId GetTypeId (void); |
| 67 |
| 68 |
| 69 //Insert value under the key. |
| 70 //Application interface (DHASH Service User) |
| 71 /** |
| 72 * \brief Insert DHash object into Chord Network |
| 73 * \param key Pointer to key array (identifier) |
| 74 * \param sizeOfKey Number of bytes in key array (max 255) |
| 75 * \param object Pointer to object byte array |
| 76 * \param sizeOfObject Number of bytes of object (max 2^32 - 1) |
| 77 * |
| 78 * See ChordIpv4::Insert |
| 79 */ |
| 80 void Insert(uint8_t *key,uint8_t sizeOfKey ,uint8_t *object,uint32_t sizeOfO
bject);···· |
| 81 /** |
| 82 * \brief Retrieves object from Chord/DHash (DHashIpv4) network represented
by given key (identifier) |
| 83 * \param key Pointer to key array (identifier) |
| 84 * \param sizeOfKey Number of bytes in key (max 255) |
| 85 * |
| 86 * See ChordIpv4::Retrieve |
| 87 */ |
| 88 |
| 89 void Retrieve (uint8_t* key, uint8_t sizeOfKey); |
| 90 /** |
| 91 * \brief See ChordIpv4::SetInsertSuccessCallback |
| 92 */ |
| 93 void SetInsertSuccessCallback (Callback <void, uint8_t*, uint8_t, uint8_t*,
uint32_t>); |
| 94 /** |
| 95 * \brief See ChordIpv4::SetRetrieveSuccessCallback |
| 96 */ |
| 97 void SetRetrieveSuccessCallback (Callback <void, uint8_t*, uint8_t, uint8_t*
, uint32_t>); |
| 98 /** |
| 99 * \brief See ChordIpv4::SetInsertFailureCallback |
| 100 */ |
| 101 void SetInsertFailureCallback (Callback <void, uint8_t*, uint8_t, uint8_t*,
uint32_t>);· |
| 102 /** |
| 103 * \brief See ChordIpv4::SetRetrieveFailureCallback |
| 104 */ |
| 105 void SetRetrieveFailureCallback (Callback <void, uint8_t*, uint8_t>); |
| 106 |
| 107 //Diagnostics interface |
| 108 /** |
| 109 * \brief See ChordIpv4::DumpDHashInfo |
| 110 */ |
| 111 void DumpDHashInfo (std::ostream &os); |
| 112 /** |
| 113 * \cond |
| 114 */ |
| 115 //Message processing methods |
| 116 void ProcessDHashMessage (Ptr<Packet> packet, Ptr<DHashConnection> dHashConn
ection); |
| 117 · |
| 118 |
| 119 //TCP callbacks |
| 120 bool HandleConnectionRequest (Ptr<Socket> socket, const Address& address); |
| 121 void HandleAccept (Ptr<Socket> socket, const Address& address); |
| 122 void HandleOwnershipTrigger (uint8_t* vNodeKey, uint8_t vNodeBytes,uint8_t*
predKey, uint8_t predBytes, uint8_t* oldPredKey, uint8_t oldPredBytes, Ipv4Addre
ss predIp, uint16_t predPort); |
| 123 void HandleClose (Ptr<Socket> socket); |
| 124 ·· |
| 125 //Periodic processes |
| 126 void DoPeriodicAuditConnections (); |
| 127 void DoPeriodicAuditObjects (); |
| 128 |
| 129 ···· |
| 130 private: |
| 131 typedef std::map<ChordIdentifier, Ptr<DHashObject> > DHashObjectMap; |
| 132 DHashObjectMap m_dHashObjectTable; |
| 133 typedef std::map<Ptr<Socket>, Ptr<DHashConnection> > DHashConnectionMap; |
| 134 DHashConnectionMap m_dHashConnectionTable; |
| 135 typedef std::map<uint32_t, Ptr<DHashTransaction> > DHashTransactionMap; |
| 136 DHashTransactionMap m_dHashTransactionTable; |
| 137 |
| 138 Ptr<ChordIpv4> m_chordApplication; |
| 139 Ipv4Address m_localIpAddress; |
| 140 uint16_t m_dHashPort; |
| 141 Ptr<Socket> m_socket; |
| 142 |
| 143 Time m_inactivityTimeout; |
| 144 Timer m_auditConnectionsTimer; |
| 145 Time m_auditObjectsTimeout; |
| 146 Timer m_auditObjectsTimer; |
| 147 |
| 148 uint32_t m_transactionId; |
| 149 //Callbacks |
| 150 Callback<void, uint8_t*, uint8_t, uint8_t*, uint32_t> m_insertSuccessFn; |
| 151 Callback<void, uint8_t*, uint8_t, uint8_t*, uint32_t> m_retrieveSuccessFn; |
| 152 Callback<void, uint8_t*, uint8_t, uint8_t*, uint32_t> m_insertFailureFn; |
| 153 Callback<void, uint8_t*, uint8_t> m_retrieveFailureFn; |
| 154 |
| 155 |
| 156 |
| 157 void SendDHashRequest (Ipv4Address ipAddress, uint16_t port, Ptr<DHashTransa
ction> dHashTransaction); |
| 158 |
| 159 //Connection Layer |
| 160 Ptr<DHashConnection> AddConnection (Ptr<Socket> socket, Ipv4Address ipAddres
s, uint16_t port); |
| 161 bool FindConnection (Ptr<Socket> m_socket, Ptr<DHashConnection> &dHashConnec
tion); |
| 162 void RemoveConnection (Ptr<Socket> socket); |
| 163 bool FindConnection (Ipv4Address ipAddress, uint16_t port, Ptr<DHashConnecti
on>& dHashConnection); |
| 164 |
| 165 |
| 166 //Object repository |
| 167 void AddObject (Ptr<DHashObject> object); |
| 168 bool FindObject (Ptr<ChordIdentifier> objectIdentifier, Ptr<DHashObject>& dH
ashObject); |
| 169 void RemoveObject (Ptr<ChordIdentifier> objectIdentifier); |
| 170 void TransferObject (Ptr<DHashObject> dHashObject, DHashTransaction::Origina
tor originator, Ipv4Address ipAddress, uint16_t port); |
| 171 |
| 172 //Transaction Layer |
| 173 void AddTransaction (Ptr<DHashTransaction> dHashTransaction); |
| 174 bool FindTransaction (uint32_t transactionId, Ptr<DHashTransaction>& dHashTr
ansaction); |
| 175 void RemoveTransaction (uint32_t transactionId); |
| 176 void RemoveActiveTransactions (Ptr<Socket> socket); |
| 177 |
| 178 //Notifications |
| 179 void NotifyInsertSuccess (Ptr<DHashObject> object); |
| 180 void NotifyRetrieveSuccess (Ptr<DHashObject> object); |
| 181 void NotifyFailure (Ptr<DHashTransaction> dHashTransaction); |
| 182 void NotifyInsertFailure (Ptr<DHashObject> object); |
| 183 void NotifyRetrieveFailure (Ptr<ChordIdentifier> objectIdentifier); |
| 184 |
| 185 |
| 186 //Packing methods |
| 187 void PackStoreReq (Ptr<DHashObject> dHashObject, DHashMessage& dHashMessage)
; |
| 188 void PackStoreRsp (uint32_t transactionId, uint8_t statusTag, Ptr<ChordIdent
ifier> objectIdentifier, DHashMessage& respMessage); |
| 189 void PackRetrieveReq (Ptr<ChordIdentifier> objectIdentifier, DHashMessage& d
HashMessage); |
| 190 void PackRetrieveRsp (uint32_t transactionId, uint8_t statusTag, Ptr<DHashOb
ject> dHashObject, DHashMessage& respMessage); |
| 191 |
| 192 |
| 193 //Processing methods |
| 194 void ProcessStoreReq (DHashMessage dHashMessage, Ptr<DHashConnection> dHashC
onnection); |
| 195 void ProcessStoreRsp (DHashMessage dHashMessage, Ptr<DHashConnection> dHashC
onnection); |
| 196 void ProcessRetrieveReq (DHashMessage dHashMessage, Ptr<DHashConnection> dHa
shConnection); |
| 197 void ProcessRetrieveRsp(DHashMessage dHashMessage, Ptr<DHashConnection> dHas
hConnection); |
| 198 |
| 199 |
| 200 //Lookup handle |
| 201 void HandleLookupFailure (uint8_t* lookupKey, uint8_t lookupKeyBytes); |
| 202 void HandleLookupSuccess (uint8_t* lookupKey, uint8_t lookupKeyBytes, Ipv4Ad
dress ipAddress, uint16_t port); |
| 203 ··· |
| 204 |
| 205 uint32_t GetNextTransactionId (); |
| 206 /** |
| 207 * \endcond |
| 208 */ |
| 209 |
| 210 }; |
| 211 |
| 212 } //namespace ns3 |
| 213 |
| 214 #endif //CHORD_IPV4_H |
OLD | NEW |