1
2 /* Web Polygraph http://www.web-polygraph.org/
3 * Copyright 2003-2011 The Measurement Factory
4 * Licensed under the Apache License, Version 2.0 */
5
6 #include "base/polygraph.h"
7
8 #include "xstd/Endian.h"
9 #include "xstd/NetAddr.h"
10 #include <sys/socket.h>
11 #include "runtime/NotifMsg.h"
12
13 #include "xstd/gadgets.h"
14 #include "base/polyLogCats.h"
15
16 /* network <-> host byte order conversions */
17
18 inline
hton(Time & t)19 void hton(Time &t) {
20 t.tv_sec = htonl(t.tv_sec);
21 t.tv_usec = htonl(t.tv_usec);
22 }
23
24 inline
ntoh(Time & t)25 void ntoh(Time &t) {
26 t.tv_sec = ntohl(t.tv_sec);
27 t.tv_usec = ntohl(t.tv_usec);
28 }
29
30 inline
hton(NetDouble & d)31 void hton(NetDouble &d) {
32 d.mnt = (int) htonl(d.mnt);
33 d.exp = (int) htonl(d.exp);
34 }
35
36 inline
ntoh(NetDouble & d)37 void ntoh(NetDouble &d) {
38 d.mnt = (int) ntohl(d.mnt);
39 d.exp = (int) ntohl(d.exp);
40 }
41
42 /* NotifMsg */
43
hton()44 void NotifMsg::hton() {
45 theId = (int) htonl(theId);
46 theSize = (int) htonl(theSize);
47 }
48
ntoh()49 void NotifMsg::ntoh() {
50 theId = (int) ntohl(theId);
51 theSize = (int) ntohl(theSize);
52 }
53
54
55 /* StatusNotifMsg */
56
StatusNotifMsg(const String & aLabel)57 StatusNotifMsg::StatusNotifMsg(const String &aLabel): NotifMsg(mtStatus) {
58 theSize = sizeof(*this);
59
60 memset(theLabel, 0, sizeof(theLabel));
61 if (aLabel)
62 strncpy(theLabel, aLabel.cstr(), sizeof(theLabel));
63
64 theXactTotCnt = theErrTotCnt = theSockInstCnt = -1;
65 theCat = lgcAll;
66 }
67
hton()68 void StatusNotifMsg::hton() {
69 NotifMsg::hton();
70
71 ::hton(theStartTime);
72 ::hton(theSndTime);
73 ::hton(theRespTime);
74
75 ::hton(theReqRate);
76 ::hton(theRepRate);
77 ::hton(theBwidth);
78 ::hton(theDHR);
79 ::hton(theConnUse);
80 ::hton(theErrRatio);
81
82 theXactTotCnt = htobe64(theXactTotCnt);
83 theErrTotCnt = htobe64(theErrTotCnt);
84 theSockInstCnt = htobe64(theSockInstCnt);
85 theCat = htonl(theCat);
86 }
87
ntoh()88 void StatusNotifMsg::ntoh() {
89 NotifMsg::ntoh();
90
91 ::ntoh(theStartTime);
92 ::ntoh(theSndTime);
93 ::ntoh(theRespTime);
94
95 ::ntoh(theReqRate);
96 ::ntoh(theRepRate);
97 ::ntoh(theBwidth);
98 ::ntoh(theDHR);
99 ::ntoh(theConnUse);
100 ::ntoh(theErrRatio);
101
102 theXactTotCnt = be64toh(theXactTotCnt);
103 theErrTotCnt = be64toh(theErrTotCnt);
104 theSockInstCnt = be64toh(theSockInstCnt);
105 theCat = ntohl(theCat);
106 }
107
108
109 /* StatusFwdMsg */
110
StatusFwdMsg()111 StatusFwdMsg::StatusFwdMsg(): theCopyCnt(-1) {
112 memset(&theSndAddr, 0, sizeof(theSndAddr));
113 theSndAddr.port = -1;
114 }
115
StatusFwdMsg(const StatusNotifMsg & m,Time aRcvTime,const NetAddr & aSndAddr)116 StatusFwdMsg::StatusFwdMsg(const StatusNotifMsg &m, Time aRcvTime, const NetAddr &aSndAddr):
117 StatusNotifMsg(m), theRcvTime(aRcvTime), theCopyCnt(-1) {
118
119 theSndAddr.addr = aSndAddr.sockAddr();
120 theSndAddr.port = aSndAddr.port();
121 }
122
hton()123 void StatusFwdMsg::hton() {
124 StatusNotifMsg::hton();
125
126 ::hton(theRcvTime);
127
128 // addr_in is always in network byte order?
129 theSndAddr.port = (int) htonl(theSndAddr.port);
130
131 theCopyCnt = (int) htonl(theCopyCnt);
132 }
133
ntoh()134 void StatusFwdMsg::ntoh() {
135 StatusNotifMsg::ntoh();
136
137 ::ntoh(theRcvTime);
138
139 // addr_in is always in network byte order?
140 theSndAddr.port = (int) ntohl(theSndAddr.port);
141
142 theCopyCnt = (int) ntohl(theCopyCnt);
143 }
144
145