forked from p4lang/p4app-switchML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
82 lines (69 loc) · 1.96 KB
/
common.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
# Copyright 2021 Intel-KAUST-Microsoft
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import re
import socket
from enum import IntEnum
# From configuration.p4
max_num_queue_pairs_per_worker = 512
# Regexes
mac_address_regex = re.compile(':'.join(['[0-9a-fA-F]{2}'] * 6))
front_panel_regex = re.compile('([0-9]+)/([0-9]+)$')
# IPv4 validation
def validate_ip(value):
''' Validate IP address string '''
try:
socket.inet_aton(value)
return True
except:
return False
# Enums
class WorkerType(IntEnum):
FORWARD_ONLY = 0
SWITCHML_UDP = 1
ROCEv2 = 2
class RDMAOpcode(IntEnum):
UC_SEND_FIRST = 0b00100000
UC_SEND_MIDDLE = 0b00100001
UC_SEND_LAST = 0b00100010
UC_SEND_LAST_IMMEDIATE = 0b00100011
UC_SEND_ONLY = 0b00100100
UC_SEND_ONLY_IMMEDIATE = 0b00100101
UC_RDMA_WRITE_FIRST = 0b00100110
UC_RDMA_WRITE_MIDDLE = 0b00100111
UC_RDMA_WRITE_LAST = 0b00101000
UC_RDMA_WRITE_LAST_IMMEDIATE = 0b00101001
UC_RDMA_WRITE_ONLY = 0b00101010
UC_RDMA_WRITE_ONLY_IMMEDIATE = 0b00101011
class PacketSize(IntEnum):
MTU_128 = 0
MTU_256 = 1
MTU_512 = 2
MTU_1024 = 3
class PacketType(IntEnum):
MIRROR = 0x0
BROADCAST = 0x1
RETRANSMIT = 0x2
IGNORE = 0x3
CONSUME0 = 0x4
CONSUME1 = 0x5
CONSUME2 = 0x6
CONSUME3 = 0x7
HARVEST0 = 0x8
HARVEST1 = 0x9
HARVEST2 = 0xa
HARVEST3 = 0xb
HARVEST4 = 0xc
HARVEST5 = 0xd
HARVEST6 = 0xe
HARVEST7 = 0xf