1 | #ifndef LowerTestAdapter_h |
---|
2 | #define LowerTestAdapter_h |
---|
3 | |
---|
4 | #include <boost/algorithm/string.hpp> |
---|
5 | #include <boost/shared_ptr.hpp> |
---|
6 | |
---|
7 | #include "Helper/Singleton.h" |
---|
8 | #include "Helper/Socket.h" |
---|
9 | #include "Helper/GeneralConfigurationParams.h" |
---|
10 | #include "Helper/Exceptions.h" |
---|
11 | #include "Ports/AdapterConfigPort.h" |
---|
12 | #include "Ports/DataPort.h" |
---|
13 | #include "Messages/TrafficCaptureMessage.h" |
---|
14 | #include "Dispatcher/Filter.h" |
---|
15 | |
---|
16 | using namespace t3devlib; |
---|
17 | |
---|
18 | class LowerTestAdapter : public Singleton<LowerTestAdapter> |
---|
19 | { |
---|
20 | private: |
---|
21 | //! Singleton pattern implementation. |
---|
22 | friend class Singleton<LowerTestAdapter>; |
---|
23 | |
---|
24 | //! LowerTestAdapter. |
---|
25 | /*! Default ctor. Shall be declared in private part due to Singleton pattern implementation. |
---|
26 | */ |
---|
27 | LowerTestAdapter(); |
---|
28 | void SendMessage(TrafficCaptureMessage * pMsg); |
---|
29 | |
---|
30 | public: |
---|
31 | ~LowerTestAdapter(); |
---|
32 | /** Register Data port to Lower Test Adapter |
---|
33 | * @param pPort: Pointer to Monitor port |
---|
34 | */ |
---|
35 | void RegisterDataPort(DataPort *pPort); |
---|
36 | |
---|
37 | /** Register AdapterConfigPort port to Lower Test Adapter |
---|
38 | * @param pPort: Pointer to Adapter port |
---|
39 | */ |
---|
40 | void RegisterAdapterConfigPort(AdapterConfigPort *pPort); |
---|
41 | |
---|
42 | /** Register a filter for a component |
---|
43 | * @param pComponent: Pointer to a ComponentId for which the filter is defined |
---|
44 | * @param filter: Filter details |
---|
45 | */ |
---|
46 | void RegisterFilter(const ComponentId *pComponent, const FilterSet & filter); |
---|
47 | |
---|
48 | //! ConnectToCaptureServer |
---|
49 | /*! Configure and connect to the TrafficCapture process |
---|
50 | * @param sServerAddress: IP address to the TrafficCapture process (it acts as a sever) |
---|
51 | * @param iServerPort: Port number |
---|
52 | * @param filter: Global traffic capture filtering |
---|
53 | * @param ifaces: Netwotrk interfaces to monitor |
---|
54 | * @param mode: Traffic capture mode: on-line / off-line |
---|
55 | * @param record: Indicate if the TrafficCapture process should record the traffic |
---|
56 | * @param fileToPlay: In offline mode, this is the Pcap file name to play. It should be set to an empty string in real-line mode. |
---|
57 | */ |
---|
58 | void ConnectToCaptureServer(boost::shared_ptr<GeneralConfigurationParams> configParams) throw (LowerTestAdapterException); |
---|
59 | //void ConnectToCaptureServer(const string& sServerAddress, const int iServerPort, const string& filter, const string& ifaces, unsigned char mode, unsigned char record, const string fileToPlay); |
---|
60 | |
---|
61 | //! ! StartCapture |
---|
62 | /*! Start the traffic capture |
---|
63 | */ |
---|
64 | void StartCapture(); |
---|
65 | |
---|
66 | //! StopCapture |
---|
67 | /*! Stop the traffic capture |
---|
68 | */ |
---|
69 | void StopCapture(); |
---|
70 | |
---|
71 | //! EnqueueMessage |
---|
72 | /*! Enqueues captured data to the component data port |
---|
73 | * @param pComp: pointer to the target component |
---|
74 | * @param pData: pointer to a buffer containing captured data |
---|
75 | * @param nDataLen: length of captured data (in bytes) |
---|
76 | */ |
---|
77 | void EnqueueMessage(const ComponentId * pComp, const unsigned char * pData, int nDataLen); |
---|
78 | |
---|
79 | private: |
---|
80 | //! ! ProcessResponse |
---|
81 | /*! Process the TrafficCapture response message result to send it to TTCN-3 script. |
---|
82 | * @param result: result code |
---|
83 | */ |
---|
84 | void ProcessResponse(const std::string& message, bool result); |
---|
85 | /* Main function for thread in charge of communication with |
---|
86 | * TrafficCapture |
---|
87 | */ |
---|
88 | static void Run(); |
---|
89 | |
---|
90 | //! InitializeCapture |
---|
91 | /*! Configure and connect to the TrafficCapture process |
---|
92 | * @param filter: Global traffic capture filtering |
---|
93 | * @param ifaces: Netwotrk interfaces to monitor |
---|
94 | * @param mode: Traffic capture mode: on-line / off-line |
---|
95 | * @param record: Indicate if the TrafficCapture process should record the traffic |
---|
96 | * @param fileToPlay: In offline mode, this is the Pcap file name to play. It should be set to an empty string in real-line mode. |
---|
97 | */ |
---|
98 | void InitializeCapture(boost::shared_ptr<GeneralConfigurationParams> configParams) throw (LowerTestAdapterException); |
---|
99 | //void InitializeCapture(const string& filter, const string& ifaces, unsigned char mode, unsigned char record, const string fileToPlay); |
---|
100 | |
---|
101 | /** This method is called whenever a captured packet is received |
---|
102 | * from TrafficCapture. It dispatches the packet to Monitor port |
---|
103 | * if associated filter matches. |
---|
104 | * @param pCapturedData: Pointer to a buffer containing captured data |
---|
105 | * @param nDataLen: Number of bytes in the buffer containing captured data |
---|
106 | */ |
---|
107 | void ProcessCapturedData(const unsigned char * pCaptureData, unsigned int nDataLen); |
---|
108 | |
---|
109 | Socket * m_captureSocket; |
---|
110 | boost::thread * m_captureThread; |
---|
111 | DataPort * m_dataPort; // created and deleted by t3dk |
---|
112 | AdapterConfigPort * m_adapterConfigPort; // created and deleted by t3dk |
---|
113 | ComponentFilter m_filter; |
---|
114 | }; |
---|
115 | |
---|
116 | |
---|
117 | #endif |
---|