-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobals.py
2640 lines (2113 loc) · 71 KB
/
globals.py
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
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file is auto-genereated by bess-gen-doc.
# See https://github.com/nemethf/bess-gen-doc
#
# It is based on bess/protobuf/module_msg.proto, which has the following copyright.
# Copyright (c) 2016-2017, Nefeli Networks, Inc.
# Copyright (c) 2017, The Regents of the University of California.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the names of the copyright holders nor the names of their
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# Based on bess version: v0.4.0-145-gbf17211d
from pybess.module import Module as BessModule # type: ignore
from pybess.port import Port # type: ignore
from pybess.bess import BESS # type: ignore
bess = BESS()
from typing import List, Any
from mypy_extensions import TypedDict
double = float
fixed32 = int
fixed64 = int
int32 = int
int64 = int
sfixed32 = int
sfixed64 = int
sint32 = int
sint64 = int
string = str
uint32 = int
uint64 = int
class AddressRange(TypedDict, total=False):
start: string
end: string
class AddressRangePair(TypedDict, total=False):
int_range: StaticNATArgAddressRange
ext_range: StaticNATArgAddressRange
class SetMetadataArgAttribute(TypedDict, total=False):
name: string
size: uint64
value_int: uint64
value_bin: bytes
offset: int32
mask: bytes
rshift_bits: int32
class BPFCommandClearArg(TypedDict, total=False):
pass
class EncapField(TypedDict, total=False):
size: uint64
attribute: string
value: FieldData
class Entry(TypedDict, total=False):
addr: string
gate: int64
class ExactMatchCommandAddArg(TypedDict, total=False):
gate: uint64
fields: List[FieldData]
class ExactMatchCommandClearArg(TypedDict, total=False):
pass
class ExactMatchConfig(TypedDict, total=False):
default_gate: uint64
rules: List[ExactMatchCommandAddArg]
class ExternalAddress(TypedDict, total=False):
ext_addr: string
port_ranges: List[PortRange]
class RandomUpdateArgField(TypedDict, total=False):
offset: int64
size: uint64
min: uint64
max: uint64
class UpdateArgField(TypedDict, total=False):
offset: int64
size: uint64
value: uint64
class Field(TypedDict, total=False):
attr_name: string
offset: uint32
num_bytes: uint32
class FieldData(TypedDict, total=False):
value_bin: bytes
value_int: uint64
class Filter(TypedDict, total=False):
priority: int64
filter: string
gate: int64
class Histogram(TypedDict, total=False):
count: uint64
above_range: uint64
resolution_ns: uint64
min_ns: uint64
avg_ns: uint64
max_ns: uint64
total_ns: uint64
percentile_values_ns: List[uint64]
class IPLookupCommandClearArg(TypedDict, total=False):
pass
class L2ForwardCommandLookupResponse(TypedDict, total=False):
gates: List[uint64]
class MeasureCommandGetSummaryResponse(TypedDict, total=False):
timestamp: double
packets: uint64
bits: uint64
latency: MeasureCommandGetSummaryResponseHistogram
jitter: MeasureCommandGetSummaryResponseHistogram
class PortRange(TypedDict, total=False):
begin: uint32
end: uint32
suspended: bool
class QueueCommandGetStatusResponse(TypedDict, total=False):
count: uint64
size: uint64
enqueued: uint64
dequeued: uint64
dropped: uint64
class RandomUpdateCommandClearArg(TypedDict, total=False):
pass
class ReadEntry(TypedDict, total=False):
key: string
value: int64
class RewriteCommandClearArg(TypedDict, total=False):
pass
class Rule(TypedDict, total=False):
src_ip: string
dst_ip: string
src_port: uint32
dst_port: uint32
established: bool
drop: bool
class UpdateCommandClearArg(TypedDict, total=False):
pass
class UpdateEntry(TypedDict, total=False):
key: string
value: int64
class Url(TypedDict, total=False):
host: string
path: string
class UrlFilterConfig(TypedDict, total=False):
blacklist: List[UrlFilterArgUrl]
class WildcardMatchCommandAddArg(TypedDict, total=False):
gate: uint64
priority: int64
values: List[FieldData]
masks: List[FieldData]
class WildcardMatchCommandClearArg(TypedDict, total=False):
pass
class WildcardMatchConfig(TypedDict, total=False):
default_gate: uint64
rules: List[WildcardMatchCommandAddArg]
class WorkerGatesEntry(TypedDict, total=False):
key: uint32
value: uint32
class WriteEntry(TypedDict, total=False):
key: string
value: int64
class ACL(BessModule):
"""
ACL module from NetBricks
The module ACL creates an access control module which by default blocks all traffic, unless it contains a rule which specifies otherwise.
Examples of ACL can be found in [acl.bess](https://github.com/NetSys/bess/blob/master/bessctl/conf/samples/acl.bess)
__Input Gates__: 1
__Output Gates__: 1
"""
def __init__(
self,
rules: List[Rule] = ...,
name: str = ...
):
"""
The module ACL creates an access control module which by default blocks all traffic, unless it contains a rule which specifies otherwise.
Examples of ACL can be found in [acl.bess](https://github.com/NetSys/bess/blob/master/bessctl/conf/samples/acl.bess)
__Input Gates__: 1
__Output Gates__: 1
:param rules: A list of ACL rules.
"""
...
def add(
self,
rules: List[Rule] = ...
):
"""
The module ACL creates an access control module which by default blocks all traffic, unless it contains a rule which specifies otherwise.
Examples of ACL can be found in [acl.bess](https://github.com/NetSys/bess/blob/master/bessctl/conf/samples/acl.bess)
__Input Gates__: 1
__Output Gates__: 1
:param rules: A list of ACL rules.
"""
...
def clear(
self
):
...
class ArpResponder(BessModule):
"""
Respond to ARP requests and learns new MAC's
The ARP Responder module is responding to ARP requests
TODO: Dynamic learn new MAC's-IP's mapping
__Input Gates__: 1
__Output Gates__: 1
"""
def __init__(
self,
ip: string = ...,
mac_addr: string = ...,
name: str = ...
):
"""
The ARP Responder module is responding to ARP requests
TODO: Dynamic learn new MAC's-IP's mapping
__Input Gates__: 1
__Output Gates__: 1
:param ip: One ARP IP-MAC mapping
The IP
:param mac_addr: The MAC address
"""
...
def add(
self,
ip: string = ...,
mac_addr: string = ...
):
"""
The ARP Responder module is responding to ARP requests
TODO: Dynamic learn new MAC's-IP's mapping
__Input Gates__: 1
__Output Gates__: 1
:param ip: One ARP IP-MAC mapping
The IP
:param mac_addr: The MAC address
"""
...
class BPF(BessModule):
"""
classifies packets with pcap-filter(7) syntax
The BPF module is an access control module that sends packets out on a particular gate based on whether they match a BPF filter.
__Input Gates__: 1
__Output Gates__: many (configurable)
"""
def __init__(
self,
filters: List[Filter] = ...,
name: str = ...
):
"""
The BPF module is an access control module that sends packets out on a particular gate based on whether they match a BPF filter.
__Input Gates__: 1
__Output Gates__: many (configurable)
:param filters: The BPF initialized function takes a list of BPF filters.
"""
...
def add(
self,
filters: List[Filter] = ...
):
"""
The BPF module is an access control module that sends packets out on a particular gate based on whether they match a BPF filter.
__Input Gates__: 1
__Output Gates__: many (configurable)
:param filters: The BPF initialized function takes a list of BPF filters.
"""
...
def clear(
self
):
"""
The BPF module has a command `clear()` that takes no parameters.
This command removes all filters from the module.
"""
...
def get_initial_arg(
self
):
...
class Buffer(BessModule):
"""
buffers packets into larger batches
The Buffer module takes no parameters to initialize (ie, `Buffer()` is sufficient to create one).
Buffer accepts packets and stores them; it may forward them to the next module only after it has
received enough packets to fill an entire PacketBatch.
__Input Gates__: 1
__Output Gates__: 1
"""
def __init__(
self,
name: str = ...
):
"""
The Buffer module takes no parameters to initialize (ie, `Buffer()` is sufficient to create one).
Buffer accepts packets and stores them; it may forward them to the next module only after it has
received enough packets to fill an entire PacketBatch.
__Input Gates__: 1
__Output Gates__: 1
"""
...
class Bypass(BessModule):
"""
bypasses packets without any processing
The Bypass module forwards packets by emulating pre-defined packet processing overhead.
It burns cpu cycles per_batch, per_packet, and per-bytes.
Bypass is useful primarily for testing and performance evaluation.
__Input Gates__: 1
__Output Gates__: 1
"""
def __init__(
self,
cycles_per_batch: uint32 = ...,
cycles_per_packet: uint32 = ...,
cycles_per_byte: uint32 = ...,
name: str = ...
):
"""
The Bypass module forwards packets by emulating pre-defined packet processing overhead.
It burns cpu cycles per_batch, per_packet, and per-bytes.
Bypass is useful primarily for testing and performance evaluation.
__Input Gates__: 1
__Output Gates__: 1
"""
...
class DRR(BessModule):
"""
Deficit Round Robin
The Module DRR provides fair scheduling of flows based on a quantum which is
number of bytes allocated to each flow on each round of going through all flows.
Examples can be found [./bessctl/conf/samples/drr.bess]
__Input_Gates__: 1
__Output_Gates__: 1
"""
def __init__(
self,
num_flows: uint32 = ...,
quantum: uint64 = ...,
max_flow_queue_size: uint32 = ...,
name: str = ...
):
"""
The Module DRR provides fair scheduling of flows based on a quantum which is
number of bytes allocated to each flow on each round of going through all flows.
Examples can be found [./bessctl/conf/samples/drr.bess]
__Input_Gates__: 1
__Output_Gates__: 1
:param num_flows: Number of flows to handle in module
:param quantum: the number of bytes to allocate to each on every round
:param max_flow_queue_size: the max size that any Flows queue can get
"""
...
def set_quantum_size(
self,
quantum: uint32 = ...
):
"""
the SetQuantumSize function sets a new quantum for DRR module to operate on.
:param quantum: the number of bytes to allocate to each on every round
"""
...
def set_max_flow_queue_size(
self,
max_queue_size: uint32 = ...
):
"""
The SetMaxQueueSize function sets a new maximum flow queue size for DRR module.
If the flow's queue gets to this size, the module starts dropping packets to
that flow until the queue is below this size.
:param max_queue_size: the max size that any Flows queue can get
"""
...
class Dump(BessModule):
"""
Dump packet data and metadata attributes
The Dump module blindly forwards packets without modifying them. It periodically samples a packet and prints out out to the BESS log (by default stored in `/tmp/bessd.INFO`).
__Input Gates__: 1
__Output Gates__: 1
"""
def __init__(
self,
interval: double = ...,
name: str = ...
):
"""
The Dump module blindly forwards packets without modifying them. It periodically samples a packet and prints out out to the BESS log (by default stored in `/tmp/bessd.INFO`).
__Input Gates__: 1
__Output Gates__: 1
:param interval: How frequently to sample and print a packet, in seconds.
"""
...
def set_interval(
self,
interval: double = ...
):
"""
The Dump module blindly forwards packets without modifying them. It periodically samples a packet and prints out out to the BESS log (by default stored in `/tmp/bessd.INFO`).
__Input Gates__: 1
__Output Gates__: 1
:param interval: How frequently to sample and print a packet, in seconds.
"""
...
class EtherEncap(BessModule):
"""
encapsulates packets with an Ethernet header
The EtherEncap module wraps packets in an Ethernet header, but it takes no parameters. Instead, Ethernet source, destination, and type are pulled from a packet's metadata attributes.
For example: `SetMetadata('dst_mac', 11:22:33:44:55) -> EtherEncap()`
This is useful when upstream modules wish to assign a MAC address to a packet, e.g., due to an ARP request.
__Input Gates__: 1
__Output Gates__: 1
"""
def __init__(
self,
name: str = ...
):
"""
The EtherEncap module wraps packets in an Ethernet header, but it takes no parameters. Instead, Ethernet source, destination, and type are pulled from a packet's metadata attributes.
For example: `SetMetadata('dst_mac', 11:22:33:44:55) -> EtherEncap()`
This is useful when upstream modules wish to assign a MAC address to a packet, e.g., due to an ARP request.
__Input Gates__: 1
__Output Gates__: 1
"""
...
class ExactMatch(BessModule):
"""
Multi-field classifier with an exact match table
The ExactMatch module splits packets along output gates according to exact match values in arbitrary packet fields.
To instantiate an ExactMatch module, you must specify which fields in the packet to match over. You can add rules using the function `ExactMatch.add(...)`
Fields may be stored either in the packet data or its metadata attributes.
An example script using the ExactMatch code is found
in [`bess/bessctl/conf/samples/exactmatch.bess`](https://github.com/NetSys/bess/blob/master/bessctl/conf/samples/exactmatch.bess).
__Input Gates__: 1
__Output Gates__: many (configurable)
"""
def __init__(
self,
fields: List[Field] = ...,
masks: List[FieldData] = ...,
name: str = ...
):
"""
The ExactMatch module splits packets along output gates according to exact match values in arbitrary packet fields.
To instantiate an ExactMatch module, you must specify which fields in the packet to match over. You can add rules using the function `ExactMatch.add(...)`
Fields may be stored either in the packet data or its metadata attributes.
An example script using the ExactMatch code is found
in [`bess/bessctl/conf/samples/exactmatch.bess`](https://github.com/NetSys/bess/blob/master/bessctl/conf/samples/exactmatch.bess).
__Input Gates__: 1
__Output Gates__: many (configurable)
:param fields: A list of ExactMatch Fields
:param masks: mask(i) corresponds to the mask for field(i)
"""
...
def get_initial_arg(
self
):
...
def get_runtime_config(
self
) -> ExactMatchConfig:
"""
:return: ExactMatchConfig represents the current runtime configuration
of an ExactMatch module, as returned by get_runtime_config and
set by set_runtime_config.
"""
...
def set_runtime_config(
self,
default_gate: uint64 = ...,
rules: List[ExactMatchCommandAddArg] = ...
):
"""
ExactMatchConfig represents the current runtime configuration
of an ExactMatch module, as returned by get_runtime_config and
set by set_runtime_config.
"""
...
def add(
self,
gate: uint64 = ...,
fields: List[FieldData] = ...
):
"""
The ExactMatch module has a command `add(...)` that takes two parameters.
The ExactMatch initializer specifies what fields in a packet to inspect; add() specifies
which values to check for over these fields.
add() inserts a new rule into the ExactMatch module such that traffic matching
that bytestring will be forwarded
out a specified gate.
Example use: `add(fields=[aton('12.3.4.5'), aton('5.4.3.2')], gate=2)`
:param gate: The gate to forward out packets that mach this rule.
:param fields: The exact match values to check for
"""
...
def delete(
self,
fields: List[FieldData] = ...
):
"""
The ExactMatch module has a command `delete(...)` which deletes an existing rule.
Example use: `delete(fields=[aton('12.3.4.5'), aton('5.4.3.2')])`
:param fields: The field values for the rule to be deleted.
"""
...
def clear(
self
):
"""
The ExactMatch module has a command `clear()` which takes no parameters.
This command removes all rules from the ExactMatch module.
"""
...
def set_default_gate(
self,
gate: uint64 = ...
):
"""
The ExactMatch module has a command `set_default_gate(...)` which takes one parameter.
This command routes all traffic which does _not_ match a rule to a specified gate.
Example use in bessctl: `setDefaultGate(gate=2)`
:param gate: The gate number to send the default traffic out.
"""
...
class FlowGen(BessModule):
"""
generates packets on a flow basis
The FlowGen module generates simulated TCP flows of packets with correct SYN/FIN flags and sequence numbers.
This module is useful for testing, e.g., a NAT module or other flow-aware code.
Packets are generated off a base, "template" packet by modifying the IP src/dst and TCP src/dst. By default, only the ports are changed and will be modified by incrementing the template ports by up to 20000 more than the template values.
__Input Gates__: 0
__Output Gates__: 1
"""
def __init__(
self,
template: bytes = ...,
pps: double = ...,
flow_rate: double = ...,
flow_duration: double = ...,
arrival: string = ...,
duration: string = ...,
quick_rampup: bool = ...,
ip_src_range: uint32 = ...,
ip_dst_range: uint32 = ...,
port_src_range: uint32 = ...,
port_dst_range: uint32 = ...,
name: str = ...
):
"""
The FlowGen module generates simulated TCP flows of packets with correct SYN/FIN flags and sequence numbers.
This module is useful for testing, e.g., a NAT module or other flow-aware code.
Packets are generated off a base, "template" packet by modifying the IP src/dst and TCP src/dst. By default, only the ports are changed and will be modified by incrementing the template ports by up to 20000 more than the template values.
__Input Gates__: 0
__Output Gates__: 1
:param template: The packet "template". All data packets are derived from this template and contain the same payload.
:param pps: The total number of packets per second to generate.
:param flow_rate: The number of new flows to create every second. flow_rate must be <= pps.
:param flow_duration: The lifetime of a flow in seconds.
:param arrival: The packet arrival distribution -- must be either "uniform" or "exponential"
:param duration: The flow duration distribution -- must be either "uniform" or "pareto"
:param quick_rampup: Whether or not to populate the flowgenerator with initial flows (start generating full pps rate immediately) or to wait for new flows to be generated naturally (all flows have a SYN packet).
:param ip_src_range: When generating new flows, FlowGen modifies the template packet by changing the IP src, incrementing it by at most ip_src_range (e.g., if the base packet is 10.0.0.1 and range is 5, it will generate packets with IPs 10.0.0.1-10.0.0.6).
:param ip_dst_range: When generating new flows, FlowGen modifies the template packet by changing the IP dst, incrementing it by at most ip_dst_range.
:param port_src_range: When generating new flows, FlowGen modifies the template packet by changing the TCP port, incrementing it by at most port_src_range.
:param port_dst_range: When generating new flows, FlowGen modifies the template packet by changing the TCP dst port, incrementing it by at most port_dst_range.
"""
...
def update(
self,
template: bytes = ...,
pps: double = ...,
flow_rate: double = ...,
flow_duration: double = ...,
arrival: string = ...,
duration: string = ...,
quick_rampup: bool = ...,
ip_src_range: uint32 = ...,
ip_dst_range: uint32 = ...,
port_src_range: uint32 = ...,
port_dst_range: uint32 = ...
):
"""
The FlowGen module generates simulated TCP flows of packets with correct SYN/FIN flags and sequence numbers.
This module is useful for testing, e.g., a NAT module or other flow-aware code.
Packets are generated off a base, "template" packet by modifying the IP src/dst and TCP src/dst. By default, only the ports are changed and will be modified by incrementing the template ports by up to 20000 more than the template values.
__Input Gates__: 0
__Output Gates__: 1
:param template: The packet "template". All data packets are derived from this template and contain the same payload.
:param pps: The total number of packets per second to generate.
:param flow_rate: The number of new flows to create every second. flow_rate must be <= pps.
:param flow_duration: The lifetime of a flow in seconds.
:param arrival: The packet arrival distribution -- must be either "uniform" or "exponential"
:param duration: The flow duration distribution -- must be either "uniform" or "pareto"
:param quick_rampup: Whether or not to populate the flowgenerator with initial flows (start generating full pps rate immediately) or to wait for new flows to be generated naturally (all flows have a SYN packet).
:param ip_src_range: When generating new flows, FlowGen modifies the template packet by changing the IP src, incrementing it by at most ip_src_range (e.g., if the base packet is 10.0.0.1 and range is 5, it will generate packets with IPs 10.0.0.1-10.0.0.6).
:param ip_dst_range: When generating new flows, FlowGen modifies the template packet by changing the IP dst, incrementing it by at most ip_dst_range.
:param port_src_range: When generating new flows, FlowGen modifies the template packet by changing the TCP port, incrementing it by at most port_src_range.
:param port_dst_range: When generating new flows, FlowGen modifies the template packet by changing the TCP dst port, incrementing it by at most port_dst_range.
"""
...
def set_burst(
self,
burst: uint64 = ...
):
"""
The FlowGen module has a command `set_burst(...)` that allows you to specify
the maximum number of packets to be stored in a single PacketBatch released
by the module.
"""
...
class GenericDecap(BessModule):
"""
remove specified bytes from the beginning of packets
The GenericDecap module strips off the first few bytes of data from a packet.
__Input Gates__: 1
__Ouptut Gates__: 1
"""
def __init__(
self,
bytes: uint64 = ...,
name: str = ...
):
"""
The GenericDecap module strips off the first few bytes of data from a packet.
__Input Gates__: 1
__Ouptut Gates__: 1
:param bytes: The number of bytes to strip off.
"""
...
class GenericEncap(BessModule):
"""
encapsulates packets with constant values and metadata attributes
The GenericEncap module adds a header to packets passing through it.
Takes a list of fields. Each field is either:
1. {'size': X, 'value': Y} (for constant values)
2. {'size': X, 'attribute': Y} (for metadata attributes)
e.g.: `GenericEncap([{'size': 4, 'value': 0xdeadbeef},
{'size': 2, 'attribute': 'foo'},
{'size': 2, 'value': 0x1234}])`
will prepend a 8-byte header:
`de ad be ef <xx> <xx> 12 34`
where the 2-byte `<xx> <xx>` comes from the value of metadata attribute `'foo'`
for each packet.
An example script using GenericEncap is in [`bess/bessctl/conf/samples/generic_encap.bess`](https://github.com/NetSys/bess/blob/master/bessctl/conf/samples/generic_encap.bess).
__Input Gates__: 1
__Output Gates__: 1
"""
def __init__(
self,
fields: List[EncapField] = ...,
name: str = ...
):
"""
The GenericEncap module adds a header to packets passing through it.
Takes a list of fields. Each field is either:
1. {'size': X, 'value': Y} (for constant values)
2. {'size': X, 'attribute': Y} (for metadata attributes)
e.g.: `GenericEncap([{'size': 4, 'value': 0xdeadbeef},
{'size': 2, 'attribute': 'foo'},
{'size': 2, 'value': 0x1234}])`
will prepend a 8-byte header:
`de ad be ef <xx> <xx> 12 34`
where the 2-byte `<xx> <xx>` comes from the value of metadata attribute `'foo'`
for each packet.
An example script using GenericEncap is in [`bess/bessctl/conf/samples/generic_encap.bess`](https://github.com/NetSys/bess/blob/master/bessctl/conf/samples/generic_encap.bess).
__Input Gates__: 1
__Output Gates__: 1
"""
...
class HashLB(BessModule):
"""
splits packets on a flow basis with L2/L3/L4 header fields
The HashLB module partitions packets between output gates according to either
a hash over their MAC src/dst (`mode='l2'`), their IP src/dst (`mode='l3'`), the full
IP/TCP 5-tuple (`mode='l4'`), or the N-tuple defined by `fields`.
__Input Gates__: 1
__Output Gates__: many (configurable)
"""
def __init__(
self,
gates: List[int64] = ...,
mode: string = ...,
fields: List[Field] = ...,
name: str = ...
):
"""
The HashLB module partitions packets between output gates according to either
a hash over their MAC src/dst (`mode='l2'`), their IP src/dst (`mode='l3'`), the full
IP/TCP 5-tuple (`mode='l4'`), or the N-tuple defined by `fields`.
__Input Gates__: 1
__Output Gates__: many (configurable)
:param gates: A list of gate numbers over which to partition packets
:param mode: The mode (`'l2'`, `'l3'`, or `'l4'`) for the hash function.
:param fields: A list of fields that define a custom tuple.
"""
...
def set_mode(
self,
mode: string = ...,
fields: List[Field] = ...
):
"""
The HashLB module has a command `set_mode(...)` which takes two parameters.
The `mode` parameter specifies whether the load balancer will hash over the
src/dest ethernet header (`'l2'`), over the src/dest IP addresses (`'l3'`), or over
the flow 5-tuple (`'l4'`). Alternatively, if the `fields` parameter is set, the
load balancer will hash over the N-tuple with the specified offsets and
sizes.
Example use in bessctl: `lb.set_mode('l2')`
:param mode: What fields to hash over, `'l2'`, `'l3'`, and `'l4'` are only valid values.
:param fields: A list of fields that define a custom tuple.
"""
...
def set_gates(
self,
gates: List[int64] = ...
):
"""
The HashLB module has a command `set_gates(...)` which takes one parameter.
This function takes in a list of gate numbers to send hashed traffic out over.
Example use in bessctl: `lb.setGates(gates=[0,1,2,3])`
:param gates: A list of gate numbers to load balance traffic over
"""
...
class IPChecksum(BessModule):
"""
recomputes the IPv4 checksum
"""
class IPEncap(BessModule):
"""
encapsulates packets with an IPv4 header
Encapsulates a packet with an IP header, where IP src, dst, and proto are filled in
by metadata values carried with the packet. Metadata attributes must include:
ip_src, ip_dst, ip_proto, ip_nexthop, and ether_type.
__Input Gates__: 1
__Output Gates__: 1
"""
def __init__(
self,
name: str = ...
):
"""
Encapsulates a packet with an IP header, where IP src, dst, and proto are filled in
by metadata values carried with the packet. Metadata attributes must include:
ip_src, ip_dst, ip_proto, ip_nexthop, and ether_type.
__Input Gates__: 1
__Output Gates__: 1
"""
...
class IPLookup(BessModule):
"""
performs Longest Prefix Match on IPv4 packets
An IPLookup module perfroms LPM lookups over a packet destination.
IPLookup takes no parameters to instantiate.
To add rules to the IPLookup table, use `IPLookup.add()`
__Input Gates__: 1
__Output Gates__: many (configurable, depending on rule values)
"""
def __init__(
self,
max_rules: uint32 = ...,
max_tbl8s: uint32 = ...,
name: str = ...
):
"""
An IPLookup module perfroms LPM lookups over a packet destination.
IPLookup takes no parameters to instantiate.
To add rules to the IPLookup table, use `IPLookup.add()`
__Input Gates__: 1
__Output Gates__: many (configurable, depending on rule values)
:param max_rules: Maximum number of rules (default: 1024)
:param max_tbl8s: Maximum number of IP prefixes with smaller than /24 (default: 128)
"""
...
def add(
self,
prefix: string = ...,
prefix_len: uint64 = ...,
gate: uint64 = ...
):
"""
The IPLookup module has a command `add(...)` which takes three paramters.
This function accepts the routing rules -- CIDR prefix, CIDR prefix length,
and what gate to forward matching traffic out on.
Example use in bessctl: `table.add(prefix='10.0.0.0', prefix_len=8, gate=2)`
:param prefix: The CIDR IP part of the prefix to match
:param prefix_len: The prefix length
:param gate: The number of the gate to forward matching traffic on.
"""
...
def delete(
self,
prefix: string = ...,
prefix_len: uint64 = ...
):
"""
The IPLookup module has a command `delete(...)` which takes two paramters.
This function accepts the routing rules -- CIDR prefix, CIDR prefix length,
Example use in bessctl: `table.delete(prefix='10.0.0.0', prefix_len=8)`
:param prefix: The CIDR IP part of the prefix to match