source: trash/old-modules/transport/omnet/AribaOmnetModule.h@ 9964

Last change on this file since 9964 was 5641, checked in by Christoph Mayer, 15 years ago
File size: 4.8 KB
RevLine 
[5641]1// [License]
2// The Ariba-Underlay Copyright
3//
4// Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
5//
6// Institute of Telematics
7// UniversitÀt Karlsruhe (TH)
8// Zirkel 2, 76128 Karlsruhe
9// Germany
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
22// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
25// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//
33// The views and conclusions contained in the software and documentation
34// are those of the authors and should not be interpreted as representing
35// official policies, either expressed or implied, of the Institute of
36// Telematics.
37// [License]
38
39#ifndef ARIBA_OMNET_MODULE_H__
40#define ARIBA_OMNET_MODULE_H__
41
42#include "ariba/utility/types.h"
43#include "ariba/utility/messages.h"
44#include "ariba/utility/types/Address.h"
45#include "ariba/utility/misc/Helper.h"
46#include "ariba/utility/logging/Logging.h"
47#include "ariba/utility/serialization/DataStream.hpp"
48#include "ariba/communication/modules/transport/TransportProtocol.h"
49#include "ariba/communication/modules/transport/TransportLocator.h"
50#include "ariba/communication/modules/network/ip/IPv4Locator.h"
51#include "AribaOmnetMessage_m.h"
52#include <omnetpp.h>
53#include <INETDefs.h>
54#include <TCPSocket.h>
55#include <map>
56#include <iostream>
57#include <sstream>
58#include <vector>
59
60using std::vector;
61using std::ostringstream;
62using std::cout;
63using std::pair;
64using std::make_pair;
65using std::map;
66using std::multimap;
67using ariba::utility::seqnum_t;
68using ariba::utility::Message;
69using ariba::utility::Address;
70using ariba::utility::serialization::data_serialize;
71using ariba::communication::IPv4Locator;
72
73namespace ariba {
74namespace communication {
75
76class INET_API AribaOmnetModule : public cSimpleModule, public TransportProtocol, TCPSocket::CallbackInterface {
77
78 use_logging_h( AribaOmnetModule );
79
80public:
81 AribaOmnetModule();
82 virtual ~AribaOmnetModule();
83
84 void setServerPort(uint16_t _port);
85
86 /**
87 * see TransportProtocol
88 */
89 virtual void start();
90 virtual void stop();
91 virtual TransportLocator::prot_t getId();
92 virtual const vector<TransportLocator*> getLocators();
93 virtual seqnum_t sendMessage( const Message* message );
94
95 /**
96 * see TCPSocket::CallbackInterface
97 */
98 virtual void socketDataArrived( int connId, void* socket, cMessage* msg, bool urgent );
99 virtual void socketFailure( int connId, void* socket, int code );
100 virtual void socketClosed( int connId, void* socket );
101 virtual void socketPeerClosed( int connId, void* socket );
102 virtual void socketEstablished( int connId, void* socket );
103 virtual void socketStatusArrived( int connId, void* socket, TCPStatusInfo *status);
104
105protected:
106 /**
107 * Called from Omnet++ on initialization of the simulation
108 */
109 virtual void initialize(int stage);
110 virtual int numInitStages () const ;
111
112 /**
113 * Called from Omnet++ during simulation:
114 * called when the module receives a message
115 */
116 virtual void handleMessage( cMessage* msg );
117
118 /** Called from Omnet++ during simulation:
119 * called when the simulation terminates.
120 * Can be used for writing statistics and the likes.
121 */
122 virtual void finish();
123
124private:
125 /**
126 * All our sockets to other nodes and the server socket
127 */
128 TCPSocket serverSocket;
129 typedef multimap<string, TCPSocket*> SocketMap;
130 SocketMap sockets;
131 uint16_t serverPort;
132
133 /**
134 * Pending data that we have to send when the socket
135 * has been opened asynchronously
136 */
137 typedef map<TCPSocket*, AribaOmnetMessage*> PendingSendQueue;
138 PendingSendQueue pendingSends;
139
140};
141
142//
143// The module class needs to be registered with OMNeT++
144//
145
146Define_Module( AribaOmnetModule );
147
148}} // namespace ariba, communication
149
150#endif // ARIBA_OMNET_MODULE_H__
Note: See TracBrowser for help on using the repository browser.