Merge pull request #1909 from esdrubal/reflection
[mono.git] / mcs / class / System / System.Net.NetworkInformation / IPv4InterfaceStatistics.cs
1 //
2 // System.Net.NetworkInformation.IPv4InterfaceStatistics
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@novell.com)
6 //      Atsushi Enomoto (atsushi@ximian.com)
7 //      Miguel de Icaza (miguel@ximian.com)
8 //
9 // Copyright (c) 2006-2008 Novell, Inc. (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 namespace System.Net.NetworkInformation {
31         class Win32IPv4InterfaceStatistics : IPv4InterfaceStatistics
32         {
33                 Win32_MIB_IFROW info;
34
35                 public Win32IPv4InterfaceStatistics (Win32_MIB_IFROW info)
36                 {
37                         this.info = info;
38                 }
39
40                 public override long BytesReceived {
41                         get { return info.InOctets; }
42                 }
43
44                 public override long BytesSent {
45                         get { return info.OutOctets; }
46                 }
47
48                 public override long IncomingPacketsDiscarded {
49                         get { return info.InDiscards; }
50                 }
51
52                 public override long IncomingPacketsWithErrors {
53                         get { return info.InErrors; }
54                 }
55
56                 public override long IncomingUnknownProtocolPackets {
57                         get { return info.InUnknownProtos; }
58                 }
59
60                 public override long NonUnicastPacketsReceived {
61                         get { return info.InNUcastPkts; }
62                 }
63
64                 public override long NonUnicastPacketsSent {
65                         get { return info.OutNUcastPkts; }
66                 }
67
68                 public override long OutgoingPacketsDiscarded {
69                         get { return info.OutDiscards; }
70                 }
71
72                 public override long OutgoingPacketsWithErrors {
73                         get { return info.OutErrors; }
74                 }
75
76                 public override long OutputQueueLength {
77                         get { return info.OutQLen; }
78                 }
79
80                 public override long UnicastPacketsReceived {
81                         get { return info.InUcastPkts; }
82                 }
83
84                 public override long UnicastPacketsSent {
85                         get { return info.OutUcastPkts; }
86                 }
87         
88         }
89
90         class LinuxIPv4InterfaceStatistics : IPv4InterfaceStatistics
91         {
92                 LinuxNetworkInterface linux;
93                 
94                 public LinuxIPv4InterfaceStatistics (LinuxNetworkInterface parent)
95                 {
96                         linux = parent;
97                 }
98
99                 long Read (string file)
100                 {
101                         try {
102                                 return long.Parse (LinuxNetworkInterface.ReadLine (linux.IfacePath + file));
103                         } catch {
104                                 return 0;
105                         }
106                 }
107                 
108                 public override long BytesReceived {
109                         get {
110                                 return Read ("statistics/rx_bytes");
111                         }
112                 }
113
114                 public override long BytesSent {
115                         get {
116                                 return Read ("statistics/tx_bytes");
117                         }
118                 }
119
120                 public override long IncomingPacketsDiscarded {
121                         get {
122                                 return Read ("statistics/rx_dropped");
123                         }
124                 }
125
126                 public override long IncomingPacketsWithErrors {
127                         get {
128                                 return Read ("statistics/rx_errors");
129                         }
130                 }
131
132                 public override long IncomingUnknownProtocolPackets {
133                         get {
134                                 // TODO
135                                 return 0;
136                         }
137                 }
138
139                 public override long NonUnicastPacketsReceived {
140                         get {
141                                 // We cant distinguish these
142                                 return Read ("statistics/multicast");
143                         }
144                 }
145
146                 public override long NonUnicastPacketsSent {
147                         get {
148                                 // We cant distinguish these
149                                 return Read ("statistics/multicast");
150                         }
151                 }
152
153                 public override long OutgoingPacketsDiscarded {
154                         get {
155                                 return Read ("statistics/tx_dropped");
156                         }
157                 }
158
159                 public override long OutgoingPacketsWithErrors {
160                         get {
161                                 return Read ("statistics/tx_errors");
162                         }
163                 }
164
165                 public override long OutputQueueLength {
166                         get {
167                                 return 1024;
168                         }
169                 }
170
171                 public override long UnicastPacketsReceived {
172                         get {
173                                 return Read ("statistics/rx_packets");
174                         }
175                 }
176
177                 public override long UnicastPacketsSent {
178                         get {
179                                 return Read ("statistics/tx_packets");
180                         }
181                 }
182         }
183
184         // dummy class
185         class MacOsIPv4InterfaceStatistics : IPv4InterfaceStatistics
186         {
187                 //MacOsNetworkInterface macos;
188                 
189                 public MacOsIPv4InterfaceStatistics (MacOsNetworkInterface parent)
190                 {
191                         //macos = parent;
192                 }
193
194                 public override long BytesReceived {
195                         get { return 0; }
196                 }
197
198                 public override long BytesSent {
199                         get { return 0; }
200                 }
201
202                 public override long IncomingPacketsDiscarded {
203                         get { return 0; }
204                 }
205
206                 public override long IncomingPacketsWithErrors {
207                         get { return 0; }
208                 }
209
210                 public override long IncomingUnknownProtocolPackets {
211                         get { return 0; }
212                 }
213
214                 public override long NonUnicastPacketsReceived {
215                         get { return 0; }
216                 }
217
218                 public override long NonUnicastPacketsSent {
219                         get { return 0; }
220                 }
221
222                 public override long OutgoingPacketsDiscarded {
223                         get { return 0; }
224                 }
225
226                 public override long OutgoingPacketsWithErrors {
227                         get { return 0; }
228                 }
229
230                 public override long OutputQueueLength {
231                         get { return 0; }
232                 }
233
234                 public override long UnicastPacketsReceived {
235                         get { return 0; }
236                 }
237
238                 public override long UnicastPacketsSent {
239                         get { return 0; }
240                 }
241         }
242         
243 }
244