-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathmultipart.go
More file actions
966 lines (851 loc) · 20.9 KB
/
multipart.go
File metadata and controls
966 lines (851 loc) · 20.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
package openflow13
import (
"encoding/binary"
log "github.com/sirupsen/logrus"
"github.com/contiv/libOpenflow/common"
"github.com/contiv/libOpenflow/util"
)
// ofp_multipart_request 1.3
type MultipartRequest struct {
common.Header
Type uint16
Flags uint16
pad []byte // 4 bytes
Body util.Message
}
func (s *MultipartRequest) Len() (n uint16) {
return s.Header.Len() + 8 + s.Body.Len()
}
func (s *MultipartRequest) MarshalBinary() (data []byte, err error) {
s.Header.Length = s.Len()
data, err = s.Header.MarshalBinary()
b := make([]byte, 8)
n := 0
binary.BigEndian.PutUint16(b[n:], s.Type)
n += 2
binary.BigEndian.PutUint16(b[n:], s.Flags)
n += 2
n += 4 // for padding
data = append(data, b...)
b, err = s.Body.MarshalBinary()
data = append(data, b...)
log.Debugf("Sending MultipartRequest (%d): %v", len(data), data)
return
}
func (s *MultipartRequest) UnmarshalBinary(data []byte) error {
err := s.Header.UnmarshalBinary(data)
n := s.Header.Len()
s.Type = binary.BigEndian.Uint16(data[n:])
n += 2
s.Flags = binary.BigEndian.Uint16(data[n:])
n += 2
n += 4 // for padding
var req util.Message
switch s.Type {
case MultipartType_Aggregate:
req = s.Body.(*AggregateStatsRequest)
err = req.UnmarshalBinary(data[n:])
case MultipartType_Desc:
break
case MultipartType_Flow:
req = s.Body.(*FlowStatsRequest)
err = req.UnmarshalBinary(data[n:])
case MultipartType_Port:
req = s.Body.(*PortStatsRequest)
err = req.UnmarshalBinary(data[n:])
case MultipartType_Table:
break
case MultipartType_Queue:
req = s.Body.(*QueueStatsRequest)
err = req.UnmarshalBinary(data[n:])
case MultipartType_Experimenter:
break
}
return err
}
// ofp_multipart_reply 1.3
type MultipartReply struct {
common.Header
Type uint16
Flags uint16
pad []byte // 4 bytes
Body []util.Message
}
func (s *MultipartReply) Len() (n uint16) {
n = s.Header.Len()
n += 8
for _, r := range s.Body {
n += uint16(r.Len())
}
return
}
func (s *MultipartReply) MarshalBinary() (data []byte, err error) {
s.Header.Length = s.Len()
data, err = s.Header.MarshalBinary()
b := make([]byte, 8)
n := 0
binary.BigEndian.PutUint16(b[n:], s.Type)
n += 2
binary.BigEndian.PutUint16(b[n:], s.Flags)
n += 2
n += 4 // for padding
data = append(data, b...)
for _, r := range s.Body {
b, err = r.MarshalBinary()
data = append(data, b...)
}
return
}
func (s *MultipartReply) UnmarshalBinary(data []byte) error {
err := s.Header.UnmarshalBinary(data)
n := s.Header.Len()
s.Type = binary.BigEndian.Uint16(data[n:])
n += 2
s.Flags = binary.BigEndian.Uint16(data[n:])
n += 2
n += 4 // for padding
var req []util.Message
for n < s.Header.Length {
var repl util.Message
switch s.Type {
case MultipartType_Aggregate:
repl = new(AggregateStats)
case MultipartType_Desc:
repl = new(DescStats)
case MultipartType_Flow:
repl = new(FlowStats)
case MultipartType_Port:
repl = new(PortStats)
case MultipartType_Table:
repl = new(TableStats)
case MultipartType_Queue:
repl = new(QueueStats)
// FIXME: Support all types
case MultipartType_Experimenter:
break
}
err = repl.UnmarshalBinary(data[n:])
if err != nil {
log.Printf("Error parsing stats reply")
}
n += repl.Len()
req = append(req, repl)
}
s.Body = req
return err
}
// ofp_multipart_request_flags & ofp_multipart_reply_flags 1.3
const (
OFPMPF_REQ_MORE = 1 << 0 /* More requests to follow. */
OFPMPF_REPLY_MORE = 1 << 0 /* More replies to follow. */
)
// _stats_types
const (
/* Description of this OpenFlow switch.
* The request body is empty.
* The reply body is struct ofp_desc_stats. */
MultipartType_Desc = iota
/* Individual flow statistics.
* The request body is struct ofp_flow_stats_request.
* The reply body is an array of struct ofp_flow_stats. */
MultipartType_Flow
/* Aggregate flow statistics.
* The request body is struct ofp_aggregate_stats_request.
* The reply body is struct ofp_aggregate_stats_reply. */
MultipartType_Aggregate
/* Flow table statistics.
* The request body is empty.
* The reply body is an array of struct ofp_table_stats. */
MultipartType_Table
/* Port statistics.
* The request body is struct ofp_port_stats_request.
* The reply body is an array of struct ofp_port_stats. */
MultipartType_Port
/* Queue statistics for a port
* The request body is struct _queue_stats_request.
* The reply body is an array of struct ofp_queue_stats */
MultipartType_Queue
/* Group counter statistics.
* The request body is struct ofp_group_stats_request.
* The reply is an array of struct ofp_group_stats. */
MultipartType_Group
/* Group description.
* The request body is empty.
* The reply body is an array of struct ofp_group_desc. */
MultipartType_GroupDesc
/* Group features.
* The request body is empty.
* The reply body is struct ofp_group_features. */
MultipartType_GroupFeatures
/* Meter statistics.
* The request body is struct ofp_meter_multipart_requests.
* The reply body is an array of struct ofp_meter_stats. */
MultipartType_Meter
/* Meter configuration.
* The request body is struct ofp_meter_multipart_requests.
* The reply body is an array of struct ofp_meter_config. */
MultipartType_MeterConfig
/* Meter features.
* The request body is empty.
* The reply body is struct ofp_meter_features. */
MultipartType_MeterFeatures
/* Table features.
* The request body is either empty or contains an array of
* struct ofp_table_features containing the controller’s
* desired view of the switch. If the switch is unable to
* set the specified view an error is returned.
* The reply body is an array of struct ofp_table_features. */
MultipartType_TableFeatures
/* Port description.
* The request body is empty.
* The reply body is an array of struct ofp_port. */
MultipartType_PortDesc
/* Experimenter extension.
* The request and reply bodies begin with
* struct ofp_experimenter_multipart_header.
* The request and reply bodies are otherwise experimenter-defined. */
MultipartType_Experimenter = 0xffff
)
// ofp_desc_stats 1.3
type DescStats struct {
MfrDesc []byte // Size DESC_STR_LEN
HWDesc []byte // Size DESC_STR_LEN
SWDesc []byte // Size DESC_STR_LEN
SerialNum []byte // Size SERIAL_NUM_LEN
DPDesc []byte // Size DESC_STR_LEN
}
func NewDescStats() *DescStats {
s := new(DescStats)
s.MfrDesc = make([]byte, DESC_STR_LEN)
s.HWDesc = make([]byte, DESC_STR_LEN)
s.SWDesc = make([]byte, DESC_STR_LEN)
s.SerialNum = make([]byte, SERIAL_NUM_LEN)
s.DPDesc = make([]byte, DESC_STR_LEN)
return s
}
func (s *DescStats) Len() (n uint16) {
return uint16(DESC_STR_LEN*4 + SERIAL_NUM_LEN)
}
func (s *DescStats) MarshalBinary() (data []byte, err error) {
data = make([]byte, int(s.Len()))
n := 0
copy(data[n:], s.MfrDesc)
n += len(s.MfrDesc)
copy(data[n:], s.HWDesc)
n += len(s.HWDesc)
copy(data[n:], s.SWDesc)
n += len(s.SWDesc)
copy(data[n:], s.SerialNum)
n += len(s.SerialNum)
copy(data[n:], s.DPDesc)
n += len(s.DPDesc)
return
}
func (s *DescStats) UnmarshalBinary(data []byte) error {
n := 0
copy(s.MfrDesc, data[n:])
n += len(s.MfrDesc)
copy(s.HWDesc, data[n:])
n += len(s.HWDesc)
copy(s.SWDesc, data[n:])
n += len(s.SWDesc)
copy(s.SerialNum, data[n:])
n += len(s.SerialNum)
copy(s.DPDesc, data[n:])
n += len(s.DPDesc)
return nil
}
const (
DESC_STR_LEN = 256
SERIAL_NUM_LEN = 32
)
const (
OFPTT_MAX = 0xfe
/* Fake tables. */
OFPTT_ALL = 0xff /* Wildcard table used for table config, flow stats and flow deletes. */
)
// ofp_flow_stats_request 1.3
type FlowStatsRequest struct {
TableId uint8
pad []byte // 3 bytes
OutPort uint32
OutGroup uint32
pad2 []byte // 4 bytes
Cookie uint64
CookieMask uint64
Match Match
}
func NewFlowStatsRequest() *FlowStatsRequest {
s := new(FlowStatsRequest)
s.OutPort = P_ANY
s.OutGroup = OFPG_ANY
s.pad = make([]byte, 3)
s.pad2 = make([]byte, 4)
s.Match = *NewMatch()
return s
}
func (s *FlowStatsRequest) Len() (n uint16) {
return s.Match.Len() + 32
}
func (s *FlowStatsRequest) MarshalBinary() (data []byte, err error) {
data = make([]byte, 32)
n := 0
data[n] = s.TableId
n += 1
copy(data[n:], s.pad)
n += 3
binary.BigEndian.PutUint32(data[n:], s.OutPort)
n += 4
binary.BigEndian.PutUint32(data[n:], s.OutGroup)
n += 4
copy(data[n:], s.pad2)
n += 4
binary.BigEndian.PutUint64(data[n:], s.Cookie)
n += 8
binary.BigEndian.PutUint64(data[n:], s.CookieMask)
n += 8
b, err := s.Match.MarshalBinary()
data = append(data, b...)
return
}
func (s *FlowStatsRequest) UnmarshalBinary(data []byte) error {
n := 0
s.TableId = data[n]
n += 1
copy(s.pad, data[n:n+3])
n += 3
s.OutPort = binary.BigEndian.Uint32(data[n:])
n += 4
s.OutGroup = binary.BigEndian.Uint32(data[n:])
n += 4
copy(s.pad2, data[n:n+4])
n += 4
s.Cookie = binary.BigEndian.Uint64(data[n:])
n += 8
s.CookieMask = binary.BigEndian.Uint64(data[n:])
n += 8
err := s.Match.UnmarshalBinary(data[n:])
n += int(s.Match.Len())
return err
}
// ofp_flow_stats 1.3
type FlowStats struct {
Length uint16
TableId uint8
pad uint8
DurationSec uint32
DurationNSec uint32
Priority uint16
IdleTimeout uint16
HardTimeout uint16
Flags uint16
pad2 []uint8 // Size 4
Cookie uint64
PacketCount uint64
ByteCount uint64
Match Match
Instructions []Instruction
}
func NewFlowStats() *FlowStats {
f := new(FlowStats)
f.Match = *NewMatch()
f.pad2 = make([]byte, 4)
f.Instructions = make([]Instruction, 0)
return f
}
func (s *FlowStats) Len() (n uint16) {
n = 48 + s.Match.Len()
for _, instr := range s.Instructions {
n += instr.Len()
}
return
}
func (s *FlowStats) MarshalBinary() (data []byte, err error) {
data = make([]byte, 48)
n := 0
binary.BigEndian.PutUint16(data[n:], s.Length)
n += 2
data[n] = s.TableId
n += 1
data[n] = s.pad
n += 1
binary.BigEndian.PutUint32(data[n:], s.DurationSec)
n += 4
binary.BigEndian.PutUint32(data[n:], s.DurationNSec)
n += 4
binary.BigEndian.PutUint16(data[n:], s.Priority)
n += 2
binary.BigEndian.PutUint16(data[n:], s.IdleTimeout)
n += 2
binary.BigEndian.PutUint16(data[n:], s.HardTimeout)
n += 2
binary.BigEndian.PutUint16(data[n:], s.Flags)
n += 2
copy(data[n:], s.pad2)
n += len(s.pad2)
binary.BigEndian.PutUint64(data[n:], s.Cookie)
n += 8
binary.BigEndian.PutUint64(data[n:], s.PacketCount)
n += 8
binary.BigEndian.PutUint64(data[n:], s.ByteCount)
n += 8
b, err := s.Match.MarshalBinary()
data = append(data, b...)
n += len(b)
for _, instr := range s.Instructions {
b, err = instr.MarshalBinary()
data = append(data, b...)
n += len(b)
}
return
}
func (s *FlowStats) UnmarshalBinary(data []byte) error {
n := 0
s.Length = binary.BigEndian.Uint16(data[n:])
n += 2
s.TableId = data[n]
n += 1
s.pad = data[n]
n += 1
s.DurationSec = binary.BigEndian.Uint32(data[n:])
n += 4
s.DurationNSec = binary.BigEndian.Uint32(data[n:])
n += 4
s.Priority = binary.BigEndian.Uint16(data[n:])
n += 2
s.IdleTimeout = binary.BigEndian.Uint16(data[n:])
n += 2
s.HardTimeout = binary.BigEndian.Uint16(data[n:])
n += 2
s.Flags = binary.BigEndian.Uint16(data[n:])
n += 2
copy(s.pad2, data[n:n+4])
n += 4
s.Cookie = binary.BigEndian.Uint64(data[n:])
n += 8
s.PacketCount = binary.BigEndian.Uint64(data[n:])
n += 8
s.ByteCount = binary.BigEndian.Uint64(data[n:])
n += 8
err := s.Match.UnmarshalBinary(data[n:])
n += int(s.Match.Len())
for n < int(s.Length) {
instr := DecodeInstr(data[n:])
s.Instructions = append(s.Instructions, instr)
n += int(instr.Len())
}
return err
}
// ofp_aggregate_stats_request 1.3
type AggregateStatsRequest struct {
TableId uint8
pad []byte // 3 bytes
OutPort uint32
OutGroup uint32
pad2 []byte // 4 bytes
Cookie uint64
CookieMask uint64
Match
}
func NewAggregateStatsRequest() *AggregateStatsRequest {
a := new(AggregateStatsRequest)
a.pad = make([]byte, 3)
a.pad2 = make([]byte, 4)
a.Match = *NewMatch()
return a
}
func (s *AggregateStatsRequest) Len() (n uint16) {
return s.Match.Len() + 32
}
func (s *AggregateStatsRequest) MarshalBinary() (data []byte, err error) {
data = make([]byte, 32)
n := 0
data[n] = s.TableId
n += 1
copy(data[n:], s.pad)
n += 3
binary.BigEndian.PutUint32(data[n:], s.OutPort)
n += 4
binary.BigEndian.PutUint32(data[n:], s.OutGroup)
n += 4
copy(data[n:], s.pad2)
n += 4
binary.BigEndian.PutUint64(data[n:], s.Cookie)
n += 8
binary.BigEndian.PutUint64(data[n:], s.CookieMask)
n += 8
b, err := s.Match.MarshalBinary()
data = append(data, b...)
return
}
func (s *AggregateStatsRequest) UnmarshalBinary(data []byte) error {
n := 0
s.TableId = data[n]
n += 1
copy(s.pad, data[n:n+3])
n += 3
s.OutPort = binary.BigEndian.Uint32(data[n:])
n += 4
s.OutGroup = binary.BigEndian.Uint32(data[n:])
n += 4
copy(s.pad2, data[n:n+4])
n += 4
s.Cookie = binary.BigEndian.Uint64(data[n:])
n += 8
s.CookieMask = binary.BigEndian.Uint64(data[n:])
n += 8
s.Match.UnmarshalBinary(data[n:])
n += int(s.Match.Len())
return nil
}
// ofp_aggregate_stats_reply 1.3
type AggregateStats struct {
PacketCount uint64
ByteCount uint64
FlowCount uint32
pad []uint8 // Size 4
}
func NewAggregateStats() *AggregateStats {
s := new(AggregateStats)
s.pad = make([]byte, 4)
return s
}
func (s *AggregateStats) Len() (n uint16) {
return 24
}
func (s *AggregateStats) MarshalBinary() (data []byte, err error) {
data = make([]byte, int(s.Len()))
n := 0
binary.BigEndian.PutUint64(data[n:], s.PacketCount)
n += 8
binary.BigEndian.PutUint64(data[n:], s.ByteCount)
n += 8
binary.BigEndian.PutUint32(data[n:], s.FlowCount)
n += 4
copy(data[n:], s.pad)
n += 4
return
}
func (s *AggregateStats) UnmarshalBinary(data []byte) error {
n := 0
s.PacketCount = binary.BigEndian.Uint64(data[n:])
n += 8
s.ByteCount = binary.BigEndian.Uint64(data[n:])
n += 8
s.FlowCount = binary.BigEndian.Uint32(data[n:])
n += 4
copy(s.pad, data[n:])
return nil
}
// FIXME: Everything below this needs to be changed for ofp1.3
// ofp_table_stats 1.0
type TableStats struct {
TableId uint8
pad []uint8 // Size 3
Name []byte // Size MAX_TABLE_NAME_LEN
Wildcards uint32
MaxEntries uint32
ActiveCount uint32
LookupCount uint64
MatchedCount uint64
}
func NewTableStats() *TableStats {
s := new(TableStats)
s.pad = make([]byte, 3)
s.Name = make([]byte, MAX_TABLE_NAME_LEN)
return s
}
func (s *TableStats) Len() (n uint16) {
return 4 + MAX_TABLE_NAME_LEN + 28
}
func (s *TableStats) MarshalBinary() (data []byte, err error) {
data = make([]byte, int(s.Len()))
n := 0
data[n] = s.TableId
n += 1
copy(data[n:], s.pad)
n += len(s.pad)
copy(data[n:], s.Name)
n += len(s.Name)
binary.BigEndian.PutUint32(data[n:], s.Wildcards)
n += 4
binary.BigEndian.PutUint32(data[n:], s.MaxEntries)
n += 4
binary.BigEndian.PutUint32(data[n:], s.ActiveCount)
n += 4
binary.BigEndian.PutUint64(data[n:], s.LookupCount)
n += 8
binary.BigEndian.PutUint64(data[n:], s.MatchedCount)
n += 8
return
}
func (s *TableStats) UnmarshalBinary(data []byte) error {
n := 0
s.TableId = data[0]
n += 1
copy(s.pad, data[n:])
n += 3
copy(s.Name, data[n:])
n += MAX_TABLE_NAME_LEN
s.Wildcards = binary.BigEndian.Uint32(data[n:])
n += 4
s.MaxEntries = binary.BigEndian.Uint32(data[n:])
n += 4
s.ActiveCount = binary.BigEndian.Uint32(data[n:])
n += 4
s.LookupCount = binary.BigEndian.Uint64(data[n:])
n += 8
s.MatchedCount = binary.BigEndian.Uint64(data[n:])
n += 8
return nil
}
const (
MAX_TABLE_NAME_LEN = 32
)
// ofp_port_stats_request 1.0
type PortStatsRequest struct {
PortNo uint16
pad []uint8 // Size 6
}
func NewPortStatsRequest() *PortStatsRequest {
p := new(PortStatsRequest)
p.pad = make([]byte, 6)
return p
}
func (s *PortStatsRequest) Len() (n uint16) {
return 8
}
func (s *PortStatsRequest) MarshalBinary() (data []byte, err error) {
data = make([]byte, int(s.Len()))
n := 0
binary.BigEndian.PutUint16(data[n:], s.PortNo)
n += 2
copy(data[n:], s.pad)
n += len(s.pad)
return
}
func (s *PortStatsRequest) UnmarshalBinary(data []byte) error {
n := 0
s.PortNo = binary.BigEndian.Uint16(data[n:])
n += 2
copy(s.pad, data[n:])
n += len(s.pad)
return nil
}
// ofp_port_stats 1.0
type PortStats struct {
PortNo uint16
pad []uint8 // Size 6
RxPackets uint64
TxPackets uint64
RxBytes uint64
TxBytes uint64
RxDropped uint64
TxDropped uint64
RxErrors uint64
TxErrors uint64
RxFrameErr uint64
RxOverErr uint64
RxCRCErr uint64
Collisions uint64
}
func NewPortStats() *PortStats {
p := new(PortStats)
p.pad = make([]byte, 6)
return p
}
func (s *PortStats) Len() (n uint16) {
return 104
}
func (s *PortStats) MarshalBinary() (data []byte, err error) {
data = make([]byte, int(s.Len()))
n := 0
binary.BigEndian.PutUint16(data[n:], s.PortNo)
n += 2
copy(data[n:], s.pad)
n += len(s.pad)
binary.BigEndian.PutUint64(data[n:], s.RxPackets)
n += 8
binary.BigEndian.PutUint64(data[n:], s.TxPackets)
n += 8
binary.BigEndian.PutUint64(data[n:], s.RxBytes)
n += 8
binary.BigEndian.PutUint64(data[n:], s.TxBytes)
n += 8
binary.BigEndian.PutUint64(data[n:], s.RxDropped)
n += 8
binary.BigEndian.PutUint64(data[n:], s.TxDropped)
n += 8
binary.BigEndian.PutUint64(data[n:], s.RxErrors)
n += 8
binary.BigEndian.PutUint64(data[n:], s.TxErrors)
n += 8
binary.BigEndian.PutUint64(data[n:], s.RxFrameErr)
n += 8
binary.BigEndian.PutUint64(data[n:], s.RxOverErr)
n += 8
binary.BigEndian.PutUint64(data[n:], s.RxCRCErr)
n += 8
binary.BigEndian.PutUint64(data[n:], s.Collisions)
n += 8
return
}
func (s *PortStats) UnmarshalBinary(data []byte) error {
n := 0
s.PortNo = binary.BigEndian.Uint16(data[n:])
n += 2
copy(s.pad, data[n:])
n += 6
s.RxPackets = binary.BigEndian.Uint64(data[n:])
n += 8
s.TxPackets = binary.BigEndian.Uint64(data[n:])
n += 8
s.RxBytes = binary.BigEndian.Uint64(data[n:])
n += 8
s.TxBytes = binary.BigEndian.Uint64(data[n:])
n += 8
s.RxDropped = binary.BigEndian.Uint64(data[n:])
n += 8
s.TxDropped = binary.BigEndian.Uint64(data[n:])
n += 8
s.RxErrors = binary.BigEndian.Uint64(data[n:])
n += 8
s.TxErrors = binary.BigEndian.Uint64(data[n:])
n += 8
s.RxFrameErr = binary.BigEndian.Uint64(data[n:])
n += 8
s.RxOverErr = binary.BigEndian.Uint64(data[n:])
n += 8
s.RxCRCErr = binary.BigEndian.Uint64(data[n:])
n += 8
s.Collisions = binary.BigEndian.Uint64(data[n:])
n += 8
return nil
}
// ofp_queue_stats_request 1.0
type QueueStatsRequest struct {
PortNo uint16
pad []uint8 // Size 2
QueueId uint32
}
func NewQueueStatsRequest() *QueueStatsRequest {
q := new(QueueStatsRequest)
q.pad = make([]byte, 2)
return q
}
func (s *QueueStatsRequest) Len() (n uint16) {
return 8
}
func (s *QueueStatsRequest) MarshalBinary() (data []byte, err error) {
data = make([]byte, int(s.Len()))
n := 0
binary.BigEndian.PutUint16(data[n:], s.PortNo)
n += 2
copy(data[n:], s.pad)
n += 2
binary.BigEndian.PutUint32(data[n:], s.QueueId)
n += 4
return
}
func (s *QueueStatsRequest) UnmarshalBinary(data []byte) error {
n := 0
s.PortNo = binary.BigEndian.Uint16(data[n:])
n += 2
copy(s.pad, data[n:])
n += 2
s.QueueId = binary.BigEndian.Uint32(data[n:])
return nil
}
// ofp_queue_stats 1.0
type QueueStats struct {
PortNo uint16
pad []uint8 // Size 2
QueueId uint32
TxBytes uint64
TxPackets uint64
TxErrors uint64
}
func (s *QueueStats) Len() (n uint16) {
return 32
}
func (s *QueueStats) MarshalBinary() (data []byte, err error) {
data = make([]byte, 32)
n := 0
binary.BigEndian.PutUint16(data[n:], s.PortNo)
n += 2
copy(data[n:], s.pad)
n += 2
binary.BigEndian.PutUint32(data[n:], s.QueueId)
n += 4
binary.BigEndian.PutUint64(data[n:], s.TxBytes)
n += 8
binary.BigEndian.PutUint64(data[n:], s.TxPackets)
n += 8
binary.BigEndian.PutUint64(data[n:], s.TxErrors)
n += 8
return
}
func (s *QueueStats) UnmarshalBinary(data []byte) error {
n := 0
s.PortNo = binary.BigEndian.Uint16(data[n:])
n += 2
copy(s.pad, data[n:])
n += 2
s.QueueId = binary.BigEndian.Uint32(data[n:])
n += 4
s.TxBytes = binary.BigEndian.Uint64(data[n:])
n += 8
s.TxPackets = binary.BigEndian.Uint64(data[n:])
n += 8
s.TxErrors = binary.BigEndian.Uint64(data[n:])
n += 8
return nil
}
// ofp_port_status
type PortStatus struct {
common.Header
Reason uint8
pad []uint8 // Size 7
Desc PhyPort
}
func NewPortStatus() *PortStatus {
p := new(PortStatus)
p.Header = NewOfp13Header()
p.pad = make([]byte, 7)
return p
}
func (p *PortStatus) Len() (n uint16) {
n = p.Header.Len()
n += 8
n += p.Desc.Len()
return
}
func (s *PortStatus) MarshalBinary() (data []byte, err error) {
s.Header.Length = s.Len()
data, err = s.Header.MarshalBinary()
b := make([]byte, 8)
n := 0
b[0] = s.Reason
n += 1
copy(b[n:], s.pad)
data = append(data, b...)
b, err = s.Desc.MarshalBinary()
data = append(data, b...)
return
}
func (s *PortStatus) UnmarshalBinary(data []byte) error {
err := s.Header.UnmarshalBinary(data)
n := int(s.Header.Len())
s.Reason = data[n]
n += 1
copy(s.pad, data[n:])
n += 7
err = s.Desc.UnmarshalBinary(data[n:])
return err
}
// ofp_port_reason 1.0
const (
PR_ADD = iota
PR_DELETE
PR_MODIFY
)