Commit a44792e6 authored by NILANJAN DAW's avatar NILANJAN DAW

Initial commit for hpdos project.

-- Implemented a MDS for routing request to replica set
-- Uses CRC32 as routing algorithm
-- Uses Key in UDP packet payload as the routing criteria
parent d01d92a2
*.pcap
.vscode/
bmv2/
p4c-bmv2/
*.pyc
server/kv.txt
controller/hot.txt
generator/hot.txt
generator/kv.txt
generator/query.txt
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -5,7 +5,7 @@ import thread
from nc_config import *
NC_PORT = 8888
NC_PORT = 8889
CLIENT_IP = "10.0.0.1"
SERVER_IP = "10.0.0.2"
CONTROLLER_IP = "10.0.0.3"
......@@ -30,16 +30,17 @@ for line in f.readlines():
line = line.split()
op = line[0]
key_header = int(line[1])
key_body = line[2:]
op_field = struct.pack("B", NC_READ_REQUEST)
op_field = struct.pack("B", 8)
key_field = struct.pack(">I", key_header)
for i in range(len(key_body)):
key_field += struct.pack("B", int(key_body[i], 16))
packet = op_field + key_field
s.sendto(packet, (SERVER_IP, NC_PORT))
counter = counter + 1
time.sleep(interval)
# break
f.close()
......@@ -5,7 +5,7 @@ import thread
from nc_config import *
NC_PORT = 8888
NC_PORT = 8889
CLIENT_IP = "10.0.0.1"
SERVER_IP = "10.0.0.2"
CONTROLLER_IP = "10.0.0.3"
......@@ -19,45 +19,48 @@ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((CONTROLLER_IP, NC_PORT))
## Initiate the switch
op = NC_UPDATE_REQUEST
op_field = struct.pack("B", op)
f = open(path_hot, "r")
for line in f.readlines():
line = line.split()
key_header = line[0]
key_body = line[1:]
# op = NC_UPDATE_REQUEST
# op_field = struct.pack("B", op)
# f = open(path_hot, "r")
# for line in f.readlines():
# line = line.split()
# key_header = line[0]
# key_body = line[1:]
key_header = int(key_header)
for i in range(len(key_body)):
key_body[i] = int(key_body[i], 16)
# key_header = int(key_header)
# for i in range(len(key_body)):
# key_body[i] = int(key_body[i], 16)
key_field = ""
key_field += struct.pack(">I", key_header)
for i in range(len(key_body)):
key_field += struct.pack("B", key_body[i])
# key_field = ""
# key_field += struct.pack(">I", key_header)
# for i in range(len(key_body)):
# key_field += struct.pack("B", key_body[i])
packet = op_field + key_field
s.sendto(packet, (SERVER_IP, NC_PORT))
time.sleep(0.001)
f.close()
# packet = op_field + key_field
# s.sendto(packet, (SERVER_IP, NC_PORT))
# time.sleep(0.001)
# f.close()
## Listen hot report
#f = open(path_log, "w")
while True:
packet, addr = s.recvfrom(2048)
# print(packet, addr)
op_field = packet[0]
key_field = packet[1:len_key + 1]
load_field = packet[len_key + 1:]
op = struct.unpack("B", op_field)[0]
if (op != NC_HOT_READ_REQUEST):
continue
# load_field = packet[len_key + 1:]
# op = struct.unpack("B", op_field)[0]
# if (op != NC_HOT_READ_REQUEST):
# continue
key_header = struct.unpack(">I", key_field[:4])[0]
load = struct.unpack(">IIII", load_field)
print(op_field, key_header)
# load = struct.unpack(">IIII", load_field)
counter = counter + 1
print "\tHot Item:", key_header, load
# counter = counter + 1
# print "\tHot Item:", key_header, load
#f.write(str(key_header) + ' ')
#f.write(str(load) + ' ')
......
table_set_default check_cache_valid check_cache_valid_act
table_set_default set_cache_valid set_cache_valid_act
table_add ipv4_route set_egress 10.0.0.1 => 1
table_add ipv4_route set_egress 10.0.0.2 => 2
table_add ipv4_route set_egress 10.0.0.3 => 3
table_add ethernet_set_mac ethernet_set_mac_act 1 => aa:bb:cc:dd:ee:11 aa:bb:cc:dd:ee:01
table_add ethernet_set_mac ethernet_set_mac_act 2 => aa:bb:cc:dd:ee:12 aa:bb:cc:dd:ee:02
table_add ethernet_set_mac ethernet_set_mac_act 3 => aa:bb:cc:dd:ee:13 aa:bb:cc:dd:ee:03
table_set_default calculate_router_hash calculate_router_hash_act
table_add update_dst update_dst_act 0 => 10.0.0.3
table_add update_dst update_dst_act 1 => 10.0.0.2
\ No newline at end of file
table_set_default check_cache_valid check_cache_valid_act
table_set_default set_cache_valid set_cache_valid_act
table_add ipv4_route set_egress 10.0.0.1 => 1
table_add ipv4_route set_egress 10.0.0.2 => 2
table_add ipv4_route set_egress 10.0.0.3 => 3
table_add ethernet_set_mac ethernet_set_mac_act 1 => aa:bb:cc:dd:ee:11 aa:bb:cc:dd:ee:01
table_add ethernet_set_mac ethernet_set_mac_act 2 => aa:bb:cc:dd:ee:12 aa:bb:cc:dd:ee:02
table_add ethernet_set_mac ethernet_set_mac_act 3 => aa:bb:cc:dd:ee:13 aa:bb:cc:dd:ee:03
table_set_default hh_load_1_count hh_load_1_count_act
table_set_default hh_load_2_count hh_load_2_count_act
table_set_default hh_load_3_count hh_load_3_count_act
table_set_default hh_load_4_count hh_load_4_count_act
table_set_default hh_bf_1 hh_bf_1_act
table_set_default hh_bf_2 hh_bf_2_act
table_set_default hh_bf_3 hh_bf_3_act
table_set_default clone_to_controller clone_to_controller_act
table_set_default report_hot report_hot_act
mirroring_add 1 1
mirroring_add 2 2
mirroring_add 3 3
table_set_default reply_read_hit_before reply_read_hit_before_act
table_set_default reply_read_hit_after reply_read_hit_after_act
table_set_default read_value_1_1 read_value_1_1_act
table_set_default add_value_header_1 add_value_header_1_act
table_set_default write_value_1_1 write_value_1_1_act
table_set_default remove_value_header_1 remove_value_header_1_act
table_set_default read_value_1_2 read_value_1_2_act
table_set_default add_value_header_1 add_value_header_1_act
table_set_default write_value_1_2 write_value_1_2_act
table_set_default remove_value_header_1 remove_value_header_1_act
table_set_default read_value_1_3 read_value_1_3_act
table_set_default add_value_header_1 add_value_header_1_act
table_set_default write_value_1_3 write_value_1_3_act
table_set_default remove_value_header_1 remove_value_header_1_act
table_set_default read_value_1_4 read_value_1_4_act
table_set_default add_value_header_1 add_value_header_1_act
table_set_default write_value_1_4 write_value_1_4_act
table_set_default remove_value_header_1 remove_value_header_1_act
table_set_default read_value_2_1 read_value_2_1_act
table_set_default add_value_header_2 add_value_header_2_act
table_set_default write_value_2_1 write_value_2_1_act
table_set_default remove_value_header_2 remove_value_header_2_act
table_set_default read_value_2_2 read_value_2_2_act
table_set_default add_value_header_2 add_value_header_2_act
table_set_default write_value_2_2 write_value_2_2_act
table_set_default remove_value_header_2 remove_value_header_2_act
table_set_default read_value_2_3 read_value_2_3_act
table_set_default add_value_header_2 add_value_header_2_act
table_set_default write_value_2_3 write_value_2_3_act
table_set_default remove_value_header_2 remove_value_header_2_act
table_set_default read_value_2_4 read_value_2_4_act
table_set_default add_value_header_2 add_value_header_2_act
table_set_default write_value_2_4 write_value_2_4_act
table_set_default remove_value_header_2 remove_value_header_2_act
table_set_default read_value_3_1 read_value_3_1_act
table_set_default add_value_header_3 add_value_header_3_act
table_set_default write_value_3_1 write_value_3_1_act
table_set_default remove_value_header_3 remove_value_header_3_act
table_set_default read_value_3_2 read_value_3_2_act
table_set_default add_value_header_3 add_value_header_3_act
table_set_default write_value_3_2 write_value_3_2_act
table_set_default remove_value_header_3 remove_value_header_3_act
table_set_default read_value_3_3 read_value_3_3_act
table_set_default add_value_header_3 add_value_header_3_act
table_set_default write_value_3_3 write_value_3_3_act
table_set_default remove_value_header_3 remove_value_header_3_act
table_set_default read_value_3_4 read_value_3_4_act
table_set_default add_value_header_3 add_value_header_3_act
table_set_default write_value_3_4 write_value_3_4_act
table_set_default remove_value_header_3 remove_value_header_3_act
table_set_default read_value_4_1 read_value_4_1_act
table_set_default add_value_header_4 add_value_header_4_act
table_set_default write_value_4_1 write_value_4_1_act
table_set_default remove_value_header_4 remove_value_header_4_act
table_set_default read_value_4_2 read_value_4_2_act
table_set_default add_value_header_4 add_value_header_4_act
table_set_default write_value_4_2 write_value_4_2_act
table_set_default remove_value_header_4 remove_value_header_4_act
table_set_default read_value_4_3 read_value_4_3_act
table_set_default add_value_header_4 add_value_header_4_act
table_set_default write_value_4_3 write_value_4_3_act
table_set_default remove_value_header_4 remove_value_header_4_act
table_set_default read_value_4_4 read_value_4_4_act
table_set_default add_value_header_4 add_value_header_4_act
table_set_default write_value_4_4 write_value_4_4_act
table_set_default remove_value_header_4 remove_value_header_4_act
table_set_default read_value_5_1 read_value_5_1_act
table_set_default add_value_header_5 add_value_header_5_act
table_set_default write_value_5_1 write_value_5_1_act
table_set_default remove_value_header_5 remove_value_header_5_act
table_set_default read_value_5_2 read_value_5_2_act
table_set_default add_value_header_5 add_value_header_5_act
table_set_default write_value_5_2 write_value_5_2_act
table_set_default remove_value_header_5 remove_value_header_5_act
table_set_default read_value_5_3 read_value_5_3_act
table_set_default add_value_header_5 add_value_header_5_act
table_set_default write_value_5_3 write_value_5_3_act
table_set_default remove_value_header_5 remove_value_header_5_act
table_set_default read_value_5_4 read_value_5_4_act
table_set_default add_value_header_5 add_value_header_5_act
table_set_default write_value_5_4 write_value_5_4_act
table_set_default remove_value_header_5 remove_value_header_5_act
table_set_default read_value_6_1 read_value_6_1_act
table_set_default add_value_header_6 add_value_header_6_act
table_set_default write_value_6_1 write_value_6_1_act
table_set_default remove_value_header_6 remove_value_header_6_act
table_set_default read_value_6_2 read_value_6_2_act
table_set_default add_value_header_6 add_value_header_6_act
table_set_default write_value_6_2 write_value_6_2_act
table_set_default remove_value_header_6 remove_value_header_6_act
table_set_default read_value_6_3 read_value_6_3_act
table_set_default add_value_header_6 add_value_header_6_act
table_set_default write_value_6_3 write_value_6_3_act
table_set_default remove_value_header_6 remove_value_header_6_act
table_set_default read_value_6_4 read_value_6_4_act
table_set_default add_value_header_6 add_value_header_6_act
table_set_default write_value_6_4 write_value_6_4_act
table_set_default remove_value_header_6 remove_value_header_6_act
table_set_default read_value_7_1 read_value_7_1_act
table_set_default add_value_header_7 add_value_header_7_act
table_set_default write_value_7_1 write_value_7_1_act
table_set_default remove_value_header_7 remove_value_header_7_act
table_set_default read_value_7_2 read_value_7_2_act
table_set_default add_value_header_7 add_value_header_7_act
table_set_default write_value_7_2 write_value_7_2_act
table_set_default remove_value_header_7 remove_value_header_7_act
table_set_default read_value_7_3 read_value_7_3_act
table_set_default add_value_header_7 add_value_header_7_act
table_set_default write_value_7_3 write_value_7_3_act
table_set_default remove_value_header_7 remove_value_header_7_act
table_set_default read_value_7_4 read_value_7_4_act
table_set_default add_value_header_7 add_value_header_7_act
table_set_default write_value_7_4 write_value_7_4_act
table_set_default remove_value_header_7 remove_value_header_7_act
table_set_default read_value_8_1 read_value_8_1_act
table_set_default add_value_header_8 add_value_header_8_act
table_set_default write_value_8_1 write_value_8_1_act
table_set_default remove_value_header_8 remove_value_header_8_act
table_set_default read_value_8_2 read_value_8_2_act
table_set_default add_value_header_8 add_value_header_8_act
table_set_default write_value_8_2 write_value_8_2_act
table_set_default remove_value_header_8 remove_value_header_8_act
table_set_default read_value_8_3 read_value_8_3_act
table_set_default add_value_header_8 add_value_header_8_act
table_set_default write_value_8_3 write_value_8_3_act
table_set_default remove_value_header_8 remove_value_header_8_act
table_set_default read_value_8_4 read_value_8_4_act
table_set_default add_value_header_8 add_value_header_8_act
table_set_default write_value_8_4 write_value_8_4_act
table_set_default remove_value_header_8 remove_value_header_8_act
table_add check_cache_exist check_cache_exist_act 79228162514264337593543950336 => 1
table_add check_cache_exist check_cache_exist_act 237684487542793012780631851008 => 3
table_add check_cache_exist check_cache_exist_act 396140812571321687967719751680 => 5
table_add check_cache_exist check_cache_exist_act 554597137599850363154807652352 => 7
table_add check_cache_exist check_cache_exist_act 713053462628379038341895553024 => 9
table_add check_cache_exist check_cache_exist_act 871509787656907713528983453696 => 11
table_add check_cache_exist check_cache_exist_act 1029966112685436388716071354368 => 13
table_add check_cache_exist check_cache_exist_act 1188422437713965063903159255040 => 15
table_add check_cache_exist check_cache_exist_act 1346878762742493739090247155712 => 17
table_add check_cache_exist check_cache_exist_act 1505335087771022414277335056384 => 19
table_add check_cache_exist check_cache_exist_act 1663791412799551089464422957056 => 21
table_add check_cache_exist check_cache_exist_act 1822247737828079764651510857728 => 23
table_add check_cache_exist check_cache_exist_act 1980704062856608439838598758400 => 25
table_add check_cache_exist check_cache_exist_act 2139160387885137115025686659072 => 27
table_add check_cache_exist check_cache_exist_act 2297616712913665790212774559744 => 29
table_add check_cache_exist check_cache_exist_act 2456073037942194465399862460416 => 31
table_add check_cache_exist check_cache_exist_act 2614529362970723140586950361088 => 33
table_add check_cache_exist check_cache_exist_act 2772985687999251815774038261760 => 35
table_add check_cache_exist check_cache_exist_act 2931442013027780490961126162432 => 37
table_add check_cache_exist check_cache_exist_act 3089898338056309166148214063104 => 39
table_add check_cache_exist check_cache_exist_act 3248354663084837841335301963776 => 41
table_add check_cache_exist check_cache_exist_act 3406810988113366516522389864448 => 43
table_add check_cache_exist check_cache_exist_act 3565267313141895191709477765120 => 45
table_add check_cache_exist check_cache_exist_act 3723723638170423866896565665792 => 47
table_add check_cache_exist check_cache_exist_act 3882179963198952542083653566464 => 49
table_add check_cache_exist check_cache_exist_act 4040636288227481217270741467136 => 51
table_add check_cache_exist check_cache_exist_act 4199092613256009892457829367808 => 53
table_add check_cache_exist check_cache_exist_act 4357548938284538567644917268480 => 55
table_add check_cache_exist check_cache_exist_act 4516005263313067242832005169152 => 57
table_add check_cache_exist check_cache_exist_act 4674461588341595918019093069824 => 59
table_add check_cache_exist check_cache_exist_act 4832917913370124593206180970496 => 61
table_add check_cache_exist check_cache_exist_act 4991374238398653268393268871168 => 63
table_add check_cache_exist check_cache_exist_act 5149830563427181943580356771840 => 65
table_add check_cache_exist check_cache_exist_act 5308286888455710618767444672512 => 67
table_add check_cache_exist check_cache_exist_act 5466743213484239293954532573184 => 69
table_add check_cache_exist check_cache_exist_act 5625199538512767969141620473856 => 71
table_add check_cache_exist check_cache_exist_act 5783655863541296644328708374528 => 73
table_add check_cache_exist check_cache_exist_act 5942112188569825319515796275200 => 75
table_add check_cache_exist check_cache_exist_act 6100568513598353994702884175872 => 77
table_add check_cache_exist check_cache_exist_act 6259024838626882669889972076544 => 79
table_add check_cache_exist check_cache_exist_act 6417481163655411345077059977216 => 81
table_add check_cache_exist check_cache_exist_act 6575937488683940020264147877888 => 83
table_add check_cache_exist check_cache_exist_act 6734393813712468695451235778560 => 85
table_add check_cache_exist check_cache_exist_act 6892850138740997370638323679232 => 87
table_add check_cache_exist check_cache_exist_act 7051306463769526045825411579904 => 89
table_add check_cache_exist check_cache_exist_act 7209762788798054721012499480576 => 91
table_add check_cache_exist check_cache_exist_act 7368219113826583396199587381248 => 93
table_add check_cache_exist check_cache_exist_act 7526675438855112071386675281920 => 95
table_add check_cache_exist check_cache_exist_act 7685131763883640746573763182592 => 97
table_add check_cache_exist check_cache_exist_act 7843588088912169421760851083264 => 99
{
"__meta__": {
"version": [
2,
5
],
"compiler": "https://github.com/p4lang/p4c-bm"
},
"header_types": [
{
"name": "standard_metadata_t",
"id": 0,
"fields": [
[
"ingress_port",
9
],
[
"packet_length",
32
],
[
"egress_spec",
9
],
[
"egress_port",
9
],
[
"egress_instance",
32
],
[
"instance_type",
32
],
[
"clone_spec",
32
],
[
"_padding",
5
]
],
"length_exp": null,
"max_length": null
},
{
"name": "ethernet_t",
"id": 1,
"fields": [
[
"dstAddr",
48
],
[
"srcAddr",
48
],
[
"etherType",
16
]
],
"length_exp": null,
"max_length": null
},
{
"name": "ipv4_t",
"id": 2,
"fields": [
[
"version",
4
],
[
"ihl",
4
],
[
"diffserv",
8
],
[
"totalLen",
16
],
[
"identification",
16
],
[
"flags",
3
],
[
"fragOffset",
13
],
[
"ttl",
8
],
[
"protocol",
8
],
[
"hdrChecksum",
16
],
[
"srcAddr",
32
],
[
"dstAddr",
32
]
],
"length_exp": null,
"max_length": null
},
{
"name": "tcp_t",
"id": 3,
"fields": [
[
"srcPort",
16
],
[
"dstPort",
16
],
[
"seqNo",
32
],
[
"ackNo",
32
],
[
"dataOffset",
4
],
[
"res",
3
],
[
"ecn",
3
],
[
"ctrl",
6
],
[
"window",
16
],
[
"checksum",
16
],
[
"urgentPtr",
16
]
],
"length_exp": null,
"max_length": null
},
{
"name": "udp_t",
"id": 4,
"fields": [
[
"srcPort",
16
],
[
"dstPort",
16
],
[
"len",
16
],
[
"checksum",
16
]
],
"length_exp": null,
"max_length": null
},
{
"name": "nc_hdr_t",
"id": 5,
"fields": [
[
"op",
8
],
[
"key",
32
]
],
"length_exp": null,
"max_length": null
},
{
"name": "router_t",
"id": 6,
"fields": [
[
"router_index",
8
]
],
"length_exp": null,
"max_length": null
}
],
"headers": [
{
"name": "standard_metadata",
"id": 0,
"header_type": "standard_metadata_t",
"metadata": true
},
{
"name": "ethernet",
"id": 1,
"header_type": "ethernet_t",
"metadata": false
},
{
"name": "ipv4",
"id": 2,
"header_type": "ipv4_t",
"metadata": false
},
{
"name": "tcp",
"id": 3,
"header_type": "tcp_t",
"metadata": false
},
{
"name": "udp",
"id": 4,
"header_type": "udp_t",
"metadata": false
},
{
"name": "nc_hdr",
"id": 5,
"header_type": "nc_hdr_t",
"metadata": false
},
{
"name": "router",
"id": 6,
"header_type": "router_t",
"metadata": true
}
],
"header_stacks": [],
"parsers": [
{
"name": "parser",
"id": 0,
"init_state": "start",
"parse_states": [
{
"name": "start",
"id": 0,
"parser_ops": [],
"transition_key": [],
"transitions": [
{
"type": "default",
"value": null,
"mask": null,
"next_state": "parse_ethernet"
}
]
},
{
"name": "parse_ethernet",
"id": 1,
"parser_ops": [
{
"op": "extract",
"parameters": [
{
"type": "regular",
"value": "ethernet"
}
]
}
],
"transition_key": [
{
"type": "field",
"value": [
"ethernet",
"etherType"
]
}
],
"transitions": [
{
"type": "hexstr",
"value": "0x0800",
"mask": null,
"next_state": "parse_ipv4"
},
{
"type": "default",
"value": null,
"mask": null,
"next_state": null
}
]
},
{
"name": "parse_ipv4",
"id": 2,
"parser_ops": [
{
"op": "extract",
"parameters": [
{
"type": "regular",
"value": "ipv4"
}
]
}
],
"transition_key": [
{
"type": "field",
"value": [
"ipv4",
"protocol"
]
}
],
"transitions": [
{
"type": "hexstr",
"value": "0x06",
"mask": null,
"next_state": "parse_tcp"
},
{
"type": "hexstr",
"value": "0x11",
"mask": null,
"next_state": "parse_udp"
},
{
"type": "default",
"value": null,
"mask": null,
"next_state": null
}
]
},
{
"name": "parse_tcp",
"id": 3,
"parser_ops": [
{
"op": "extract",
"parameters": [
{
"type": "regular",
"value": "tcp"
}
]
}
],
"transition_key": [],
"transitions": [
{
"type": "default",
"value": null,
"mask": null,
"next_state": null
}
]
},
{
"name": "parse_udp",
"id": 4,
"parser_ops": [
{
"op": "extract",
"parameters": [
{
"type": "regular",
"value": "udp"
}
]
}
],
"transition_key": [
{
"type": "field",
"value": [
"udp",
"dstPort"
]
}
],
"transitions": [
{
"type": "hexstr",
"value": "0x1f99",
"mask": null,
"next_state": "parse_nc_hdr"
},
{
"type": "default",
"value": null,
"mask": null,
"next_state": "parse_nc_hdr"
}
]
},
{
"name": "parse_nc_hdr",
"id": 5,
"parser_ops": [
{
"op": "extract",
"parameters": [
{
"type": "regular",
"value": "nc_hdr"
}
]
}
],
"transition_key": [
{
"type": "field",
"value": [
"nc_hdr",
"op"
]
}
],
"transitions": [
{
"type": "hexstr",
"value": "0x00",
"mask": null,
"next_state": null
},
{
"type": "default",
"value": null,
"mask": null,
"next_state": null
}
]
}
]
}
],
"parse_vsets": [],
"deparsers": [
{
"name": "deparser",
"id": 0,
"order": [
"ethernet",
"ipv4",
"udp",
"nc_hdr",
"tcp"
]
}
],
"meter_arrays": [],
"actions": [
{
"name": "ethernet_set_mac_act",
"id": 0,
"runtime_data": [
{
"name": "smac",
"bitwidth": 48
},
{
"name": "dmac",
"bitwidth": 48
}
],
"primitives": [
{
"op": "modify_field",
"parameters": [
{
"type": "field",
"value": [
"ethernet",
"srcAddr"
]
},
{
"type": "runtime_data",
"value": 0
}
]
},
{
"op": "modify_field",
"parameters": [
{
"type": "field",
"value": [
"ethernet",
"dstAddr"
]
},
{
"type": "runtime_data",
"value": 1
}
]
}
]
},
{
"name": "set_egress",
"id": 1,
"runtime_data": [
{
"name": "egress_spec",
"bitwidth": 9
}
],
"primitives": [
{
"op": "modify_field",
"parameters": [
{
"type": "field",
"value": [
"standard_metadata",
"egress_spec"
]
},
{
"type": "runtime_data",
"value": 0
}
]
},
{
"op": "add_to_field",
"parameters": [
{
"type": "field",
"value": [
"ipv4",
"ttl"
]
},
{
"type": "hexstr",
"value": "-0x1"
}
]
}
]
},
{
"name": "calculate_router_hash_act",
"id": 2,
"runtime_data": [],
"primitives": [
{
"op": "modify_field_with_hash_based_offset",
"parameters": [
{
"type": "field",
"value": [
"router",
"router_index"
]
},
{
"type": "hexstr",
"value": "0x0"
},
{
"type": "calculation",
"value": "router_hash"
},
{
"type": "hexstr",
"value": "0x2"
}
]
}
]
},
{
"name": "update_dst_act",
"id": 3,
"runtime_data": [
{
"name": "dstAddr",
"bitwidth": 32
}
],
"primitives": [
{
"op": "modify_field",
"parameters": [
{
"type": "field",
"value": [
"ipv4",
"dstAddr"
]
},
{
"type": "runtime_data",
"value": 0
}
]
}
]
}
],
"pipelines": [
{
"name": "ingress",
"id": 0,
"init_table": "calculate_router_hash",
"tables": [
{
"name": "ipv4_route",
"id": 0,
"match_type": "exact",
"type": "simple",
"max_size": 8192,
"with_counters": false,
"direct_meters": null,
"support_timeout": false,
"key": [
{
"match_type": "exact",
"target": [
"ipv4",
"dstAddr"
],
"mask": null
}
],
"actions": [
"set_egress"
],
"next_tables": {
"set_egress": null
},
"base_default_next": null
},
{
"name": "update_dst",
"id": 1,
"match_type": "exact",
"type": "simple",
"max_size": 16384,
"with_counters": false,
"direct_meters": null,
"support_timeout": false,
"key": [
{
"match_type": "exact",
"target": [
"router",
"router_index"
],
"mask": null
}
],
"actions": [
"update_dst_act"
],
"next_tables": {
"update_dst_act": "ipv4_route"
},
"base_default_next": "ipv4_route"
},
{
"name": "calculate_router_hash",
"id": 2,
"match_type": "exact",
"type": "simple",
"max_size": 16384,
"with_counters": false,
"direct_meters": null,
"support_timeout": false,
"key": [],
"actions": [
"calculate_router_hash_act"
],
"next_tables": {
"calculate_router_hash_act": "update_dst"
},
"base_default_next": "update_dst"
}
],
"action_profiles": [],
"conditionals": []
},
{
"name": "egress",
"id": 1,
"init_table": "ethernet_set_mac",
"tables": [
{
"name": "ethernet_set_mac",
"id": 3,
"match_type": "exact",
"type": "simple",
"max_size": 16384,
"with_counters": false,
"direct_meters": null,
"support_timeout": false,
"key": [
{
"match_type": "exact",
"target": [
"standard_metadata",
"egress_port"
],
"mask": null
}
],
"actions": [
"ethernet_set_mac_act"
],
"next_tables": {
"ethernet_set_mac_act": null
},
"base_default_next": null
}
],
"action_profiles": [],
"conditionals": []
}
],
"calculations": [
{
"name": "ipv4_chksum_calc",
"id": 0,
"input": [
{
"type": "field",
"value": [
"ipv4",
"version"
]
},
{
"type": "field",
"value": [
"ipv4",
"ihl"
]
},
{
"type": "field",
"value": [
"ipv4",
"diffserv"
]
},
{
"type": "field",
"value": [
"ipv4",
"totalLen"
]
},
{
"type": "field",
"value": [
"ipv4",
"identification"
]
},
{
"type": "field",
"value": [
"ipv4",
"flags"
]
},
{
"type": "field",
"value": [
"ipv4",
"fragOffset"
]
},
{
"type": "field",
"value": [
"ipv4",
"ttl"
]
},
{
"type": "field",
"value": [
"ipv4",
"protocol"
]
},
{
"type": "field",
"value": [
"ipv4",
"srcAddr"
]
},
{
"type": "field",
"value": [
"ipv4",
"dstAddr"
]
}
],
"algo": "csum16"
},
{
"name": "udp_checksum",
"id": 1,
"input": [
{
"type": "field",
"value": [
"ipv4",
"srcAddr"
]
},
{
"type": "field",
"value": [
"ipv4",
"dstAddr"
]
},
{
"type": "hexstr",
"value": "0x00",
"bitwidth": 8
},
{
"type": "field",
"value": [
"ipv4",
"protocol"
]
},
{
"type": "field",
"value": [
"udp",
"len"
]
},
{
"type": "field",
"value": [
"udp",
"srcPort"
]
},
{
"type": "field",
"value": [
"udp",
"dstPort"
]
},
{
"type": "field",
"value": [
"udp",
"len"
]
},
{
"type": "header",
"value": "nc_hdr"
},
{
"type": "header",
"value": "tcp"
},
{
"type": "payload"
}
],
"algo": "csum16"
},
{
"name": "router_hash",
"id": 2,
"input": [
{
"type": "field",
"value": [
"nc_hdr",
"key"
]
}
],
"algo": "crc32"
}
],
"checksums": [
{
"name": "ipv4.hdrChecksum|ipv4_chksum_calc",
"id": 0,
"target": [
"ipv4",
"hdrChecksum"
],
"type": "generic",
"calculation": "ipv4_chksum_calc",
"if_cond": null
},
{
"name": "udp.checksum|udp_checksum",
"id": 1,
"target": [
"udp",
"checksum"
],
"type": "generic",
"calculation": "udp_checksum",
"if_cond": null
}
],
"learn_lists": [],
"field_lists": [],
"counter_arrays": [],
"register_arrays": [],
"force_arith": [
[
"standard_metadata",
"ingress_port"
],
[
"standard_metadata",
"packet_length"
],
[
"standard_metadata",
"egress_spec"
],
[
"standard_metadata",
"egress_port"
],
[
"standard_metadata",
"egress_instance"
],
[
"standard_metadata",
"instance_type"
],
[
"standard_metadata",
"clone_spec"
],
[
"standard_metadata",
"_padding"
]
]
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -24,10 +24,10 @@ SWITCH_PATH=$BMV2_PATH/targets/simple_switch/simple_switch
#CLI_PATH=$BMV2_PATH/tools/runtime_CLI.py
CLI_PATH=$BMV2_PATH/targets/simple_switch/sswitch_CLI
$P4C_BM_SCRIPT ../p4src/netcache.p4 --json netcache.json
$P4C_BM_SCRIPT ../p4src/hpdos.p4 --json hpdos.json
# This gives libtool the opportunity to "warm-up"
sudo $SWITCH_PATH >/dev/null 2>&1
# sudo $SWITCH_PATH >/dev/null 2>&1
sudo PYTHONPATH=$PYTHONPATH:$BMV2_PATH/mininet/ python topo.py \
--behavioral-exe $SWITCH_PATH \
--json netcache.json \
--json hpdos.json \
--cli $CLI_PATH
......@@ -115,7 +115,7 @@ def main():
for i in range(nb_switches):
#cmd = [args.cli, "--json", args.json, "--thrift-port", str(_THRIFT_BASE_PORT + i)]
cmd = [args.cli, args.json, str(_THRIFT_BASE_PORT + i)]
with open("commands.txt", "r") as f:
with open("c.txt", "r") as f:
print " ".join(cmd)
try:
output = subprocess.check_output(cmd, stdin = f)
......
header_type nc_cache_md_t {
fields {
cache_exist: 1;
cache_index: 14;
cache_valid: 1;
}
}
metadata nc_cache_md_t nc_cache_md;
action check_cache_exist_act(index) {
modify_field (nc_cache_md.cache_exist, 1);
modify_field (nc_cache_md.cache_index, index);
}
table check_cache_exist {
reads {
nc_hdr.key: exact;
}
actions {
check_cache_exist_act;
}
size: NUM_CACHE;
}
register cache_valid_reg {
width: 1;
instance_count: NUM_CACHE;
}
action check_cache_valid_act() {
register_read(nc_cache_md.cache_valid, cache_valid_reg, nc_cache_md.cache_index);
}
table check_cache_valid {
actions {
check_cache_valid_act;
}
//default_action: check_cache_valid_act;
}
action set_cache_valid_act() {
register_write(cache_valid_reg, nc_cache_md.cache_index, 1);
}
table set_cache_valid {
actions {
set_cache_valid_act;
}
//default_action: set_cache_valid_act;
}
control process_cache {
apply (check_cache_exist);
if (nc_cache_md.cache_exist == 1) {
if (nc_hdr.op == NC_READ_REQUEST) {
apply (check_cache_valid);
}
else if (nc_hdr.op == NC_UPDATE_REPLY) {
apply (set_cache_valid);
}
}
}
#define HH_LOAD_WIDTH 32
#define HH_LOAD_NUM 256
#define HH_LOAD_HASH_WIDTH 8
#define HH_THRESHOLD 128
#define HH_BF_NUM 512
#define HH_BF_HASH_WIDTH 9
header_type nc_load_md_t {
fields {
index_1: 16;
index_2: 16;
index_3: 16;
index_4: 16;
load_1: 32;
load_2: 32;
load_3: 32;
load_4: 32;
}
}
metadata nc_load_md_t nc_load_md;
field_list hh_hash_fields {
nc_hdr.key;
}
register hh_load_1_reg {
width: HH_LOAD_WIDTH;
instance_count: HH_LOAD_NUM;
}
field_list_calculation hh_load_1_hash {
input {
hh_hash_fields;
}
algorithm : crc32;
output_width : HH_LOAD_HASH_WIDTH;
}
action hh_load_1_count_act() {
modify_field_with_hash_based_offset(nc_load_md.index_1, 0, hh_load_1_hash, HH_LOAD_NUM);
register_read(nc_load_md.load_1, hh_load_1_reg, nc_load_md.index_1);
register_write(hh_load_1_reg, nc_load_md.index_1, nc_load_md.load_1 + 1);
}
table hh_load_1_count {
actions {
hh_load_1_count_act;
}
}
register hh_load_2_reg {
width: HH_LOAD_WIDTH;
instance_count: HH_LOAD_NUM;
}
field_list_calculation hh_load_2_hash {
input {
hh_hash_fields;
}
algorithm : csum16;
output_width : HH_LOAD_HASH_WIDTH;
}
action hh_load_2_count_act() {
modify_field_with_hash_based_offset(nc_load_md.index_2, 0, hh_load_2_hash, HH_LOAD_NUM);
register_read(nc_load_md.load_2, hh_load_2_reg, nc_load_md.index_2);
register_write(hh_load_2_reg, nc_load_md.index_2, nc_load_md.load_2 + 1);
}
table hh_load_2_count {
actions {
hh_load_2_count_act;
}
}
register hh_load_3_reg {
width: HH_LOAD_WIDTH;
instance_count: HH_LOAD_NUM;
}
field_list_calculation hh_load_3_hash {
input {
hh_hash_fields;
}
algorithm : crc16;
output_width : HH_LOAD_HASH_WIDTH;
}
action hh_load_3_count_act() {
modify_field_with_hash_based_offset(nc_load_md.index_3, 0, hh_load_3_hash, HH_LOAD_NUM);
register_read(nc_load_md.load_3, hh_load_3_reg, nc_load_md.index_3);
register_write(hh_load_3_reg, nc_load_md.index_3, nc_load_md.load_3 + 1);
}
table hh_load_3_count {
actions {
hh_load_3_count_act;
}
}
register hh_load_4_reg {
width: HH_LOAD_WIDTH;
instance_count: HH_LOAD_NUM;
}
field_list_calculation hh_load_4_hash {
input {
hh_hash_fields;
}
algorithm : crc32;
output_width : HH_LOAD_HASH_WIDTH;
}
action hh_load_4_count_act() {
modify_field_with_hash_based_offset(nc_load_md.index_4, 0, hh_load_4_hash, HH_LOAD_NUM);
register_read(nc_load_md.load_4, hh_load_4_reg, nc_load_md.index_4);
register_write(hh_load_4_reg, nc_load_md.index_4, nc_load_md.load_4 + 1);
}
table hh_load_4_count {
actions {
hh_load_4_count_act;
}
}
control count_min {
apply (hh_load_1_count);
apply (hh_load_2_count);
apply (hh_load_3_count);
apply (hh_load_4_count);
}
header_type hh_bf_md_t {
fields {
index_1: 16;
index_2: 16;
index_3: 16;
bf_1: 1;
bf_2: 1;
bf_3: 1;
}
}
metadata hh_bf_md_t hh_bf_md;
register hh_bf_1_reg {
width: 1;
instance_count: HH_BF_NUM;
}
field_list_calculation hh_bf_1_hash {
input {
hh_hash_fields;
}
algorithm : crc32;
output_width : HH_BF_HASH_WIDTH;
}
action hh_bf_1_act() {
modify_field_with_hash_based_offset(hh_bf_md.index_1, 0, hh_bf_1_hash, HH_BF_NUM);
register_read(hh_bf_md.bf_1, hh_bf_1_reg, hh_bf_md.index_1);
register_write(hh_bf_1_reg, hh_bf_md.index_1, 1);
}
table hh_bf_1 {
actions {
hh_bf_1_act;
}
}
register hh_bf_2_reg {
width: 1;
instance_count: HH_BF_NUM;
}
field_list_calculation hh_bf_2_hash {
input {
hh_hash_fields;
}
algorithm : csum16;
output_width : HH_BF_HASH_WIDTH;
}
action hh_bf_2_act() {
modify_field_with_hash_based_offset(hh_bf_md.index_2, 0, hh_bf_2_hash, HH_BF_NUM);
register_read(hh_bf_md.bf_2, hh_bf_2_reg, hh_bf_md.index_2);
register_write(hh_bf_2_reg, hh_bf_md.index_2, 1);
}
table hh_bf_2 {
actions {
hh_bf_2_act;
}
}
register hh_bf_3_reg {
width: 1;
instance_count: HH_BF_NUM;
}
field_list_calculation hh_bf_3_hash {
input {
hh_hash_fields;
}
algorithm : crc16;
output_width : HH_BF_HASH_WIDTH;
}
action hh_bf_3_act() {
modify_field_with_hash_based_offset(hh_bf_md.index_3, 0, hh_bf_3_hash, HH_BF_NUM);
register_read(hh_bf_md.bf_3, hh_bf_3_reg, hh_bf_md.index_3);
register_write(hh_bf_3_reg, hh_bf_md.index_3, 1);
}
table hh_bf_3 {
actions {
hh_bf_3_act;
}
}
control bloom_filter {
apply (hh_bf_1);
apply (hh_bf_2);
apply (hh_bf_3);
}
field_list mirror_list {
nc_load_md.load_1;
nc_load_md.load_2;
nc_load_md.load_3;
nc_load_md.load_4;
}
#define CONTROLLER_MIRROR_DSET 3
action clone_to_controller_act() {
clone_egress_pkt_to_egress(CONTROLLER_MIRROR_DSET, mirror_list);
}
table clone_to_controller {
actions {
clone_to_controller_act;
}
}
control report_hot_step_1 {
apply (clone_to_controller);
}
#define CONTROLLER_IP 0x0a000003
action report_hot_act() {
modify_field (nc_hdr.op, NC_HOT_READ_REQUEST);
add_header (nc_load);
add_to_field(ipv4.totalLen, 16);
add_to_field(udp.len, 16);
modify_field (nc_load.load_1, nc_load_md.load_1);
modify_field (nc_load.load_2, nc_load_md.load_2);
modify_field (nc_load.load_3, nc_load_md.load_3);
modify_field (nc_load.load_4, nc_load_md.load_4);
modify_field (ipv4.dstAddr, CONTROLLER_IP);
}
table report_hot {
actions {
report_hot_act;
}
}
control report_hot_step_2 {
apply (report_hot);
}
control heavy_hitter {
if (standard_metadata.instance_type == 0) {
count_min();
if (nc_load_md.load_1 > HH_THRESHOLD) {
if (nc_load_md.load_2 > HH_THRESHOLD) {
if (nc_load_md.load_3 > HH_THRESHOLD) {
if (nc_load_md.load_4 > HH_THRESHOLD) {
bloom_filter();
if (hh_bf_md.bf_1 == 0 or hh_bf_md.bf_2 == 0 or hh_bf_md.bf_3 == 0){
report_hot_step_1();
}
}
}
}
}
}
else {
report_hot_step_2();
}
}
......@@ -2,23 +2,15 @@
#include "includes/headers.p4"
#include "includes/parsers.p4"
#include "includes/checksum.p4"
#include "cache.p4"
#include "heavy_hitter.p4"
#include "value.p4"
#include "ipv4.p4"
#include "ethernet.p4"
#include "ipv4.p4"
#include "mds.p4"
control ingress {
process_cache();
process_value();
apply (ipv4_route);
routePacket();
apply(ipv4_route);
}
control egress {
if (nc_hdr.op == NC_READ_REQUEST and nc_cache_md.cache_exist != 1) {
heavy_hitter();
}
apply (ethernet_set_mac);
}
apply(ethernet_set_mac);
}
\ No newline at end of file
#define NC_PORT 8888
#define SILLY_PORT 8089
#define NUM_CACHE 128
#define NC_READ_REQUEST 0
......
......@@ -55,7 +55,7 @@ header udp_t udp;
header_type nc_hdr_t {
fields {
op: 8;
key: 128;
key: 32;
}
}
header nc_hdr_t nc_hdr;
......
......@@ -30,8 +30,9 @@ parser parse_tcp {
parser parse_udp {
extract (udp);
return select (latest.dstPort) {
NC_PORT: parse_nc_hdr;
default: ingress;
// NC_PORT: drop;
SILLY_PORT: parse_nc_hdr;
default: parse_nc_hdr;
}
}
......@@ -39,23 +40,10 @@ parser parse_nc_hdr {
extract (nc_hdr);
return select(latest.op) {
NC_READ_REQUEST: ingress;
NC_READ_REPLY: parse_value;
NC_HOT_READ_REQUEST: parse_nc_load;
NC_UPDATE_REQUEST: ingress;
NC_UPDATE_REPLY: parse_value;
default: ingress;
}
}
parser parse_nc_load {
extract (nc_load);
return ingress;
}
parser parse_value {
return parse_nc_value_1;
}
/*
The parsers for value headers are defined in value.p4
k = 1, 2, ..., 8
......
#define CLUSTER_COUNT 2
#define ROUTER_HASH_WIDTH 8
header_type router_t {
fields {
router_index: 8;
}
}
metadata router_t router;
action update_dst_act(dstAddr) {
modify_field (ipv4.dstAddr, dstAddr);
}
table update_dst {
reads {
router.router_index: exact;
}
actions {
update_dst_act;
}
}
field_list router_hash_fields {
nc_hdr.key;
}
field_list_calculation router_hash {
input {
router_hash_fields;
}
algorithm : crc32;
output_width : ROUTER_HASH_WIDTH;
}
action calculate_router_hash_act() {
modify_field_with_hash_based_offset(router.router_index, 0, router_hash, CLUSTER_COUNT);
}
table calculate_router_hash {
actions {
calculate_router_hash_act;
}
}
control routePacket {
apply(calculate_router_hash);
apply(update_dst);
}
#define HEADER_VALUE(i) \
header_type nc_value_##i##_t { \
fields { \
value_##i##_1: 32; \
value_##i##_2: 32; \
value_##i##_3: 32; \
value_##i##_4: 32; \
} \
} \
header nc_value_##i##_t nc_value_##i;
#define PARSER_VALUE(i, ip1) \
parser parse_nc_value_##i { \
extract (nc_value_##i); \
return parse_nc_value_##ip1; \
}
#define REGISTER_VALUE_SLICE(i, j) \
register value_##i##_##j##_reg { \
width: 32; \
instance_count: NUM_CACHE; \
}
#define REGISTER_VALUE(i) \
REGISTER_VALUE_SLICE(i, 1) \
REGISTER_VALUE_SLICE(i, 2) \
REGISTER_VALUE_SLICE(i, 3) \
REGISTER_VALUE_SLICE(i, 4)
#define ACTION_READ_VALUE_SLICE(i, j) \
action read_value_##i##_##j##_act() { \
register_read(nc_value_##i.value_##i##_##j, value_##i##_##j##_reg, nc_cache_md.cache_index); \
}
#define ACTION_READ_VALUE(i) \
ACTION_READ_VALUE_SLICE(i, 1) \
ACTION_READ_VALUE_SLICE(i, 2) \
ACTION_READ_VALUE_SLICE(i, 3) \
ACTION_READ_VALUE_SLICE(i, 4)
#define TABLE_READ_VALUE_SLICE(i, j) \
table read_value_##i##_##j { \
actions { \
read_value_##i##_##j##_act; \
} \
}
#define TABLE_READ_VALUE(i) \
TABLE_READ_VALUE_SLICE(i, 1) \
TABLE_READ_VALUE_SLICE(i, 2) \
TABLE_READ_VALUE_SLICE(i, 3) \
TABLE_READ_VALUE_SLICE(i, 4)
#define ACTION_ADD_VALUE_HEADER(i) \
action add_value_header_##i##_act() { \
add_to_field(ipv4.totalLen, 16);\
add_to_field(udp.len, 16);\
add_header(nc_value_##i); \
}
#define TABLE_ADD_VALUE_HEADER(i) \
table add_value_header_##i { \
actions { \
add_value_header_##i##_act; \
} \
}
#define ACTION_WRITE_VALUE_SLICE(i, j) \
action write_value_##i##_##j##_act() { \
register_write(value_##i##_##j##_reg, nc_cache_md.cache_index, nc_value_##i.value_##i##_##j); \
}
#define ACTION_WRITE_VALUE(i) \
ACTION_WRITE_VALUE_SLICE(i, 1) \
ACTION_WRITE_VALUE_SLICE(i, 2) \
ACTION_WRITE_VALUE_SLICE(i, 3) \
ACTION_WRITE_VALUE_SLICE(i, 4)
#define TABLE_WRITE_VALUE_SLICE(i, j) \
table write_value_##i##_##j { \
actions { \
write_value_##i##_##j##_act; \
} \
}
#define TABLE_WRITE_VALUE(i) \
TABLE_WRITE_VALUE_SLICE(i, 1) \
TABLE_WRITE_VALUE_SLICE(i, 2) \
TABLE_WRITE_VALUE_SLICE(i, 3) \
TABLE_WRITE_VALUE_SLICE(i, 4)
#define ACTION_REMOVE_VALUE_HEADER(i) \
action remove_value_header_##i##_act() { \
subtract_from_field(ipv4.totalLen, 16);\
subtract_from_field(udp.len, 16);\
remove_header(nc_value_##i); \
}
#define TABLE_REMOVE_VALUE_HEADER(i) \
table remove_value_header_##i { \
actions { \
remove_value_header_##i##_act; \
} \
}
#define CONTROL_PROCESS_VALUE(i) \
control process_value_##i { \
if (nc_hdr.op == NC_READ_REQUEST and nc_cache_md.cache_valid == 1) { \
apply (add_value_header_##i); \
apply (read_value_##i##_1); \
apply (read_value_##i##_2); \
apply (read_value_##i##_3); \
apply (read_value_##i##_4); \
} \
else if (nc_hdr.op == NC_UPDATE_REPLY and nc_cache_md.cache_exist == 1) { \
apply (write_value_##i##_1); \
apply (write_value_##i##_2); \
apply (write_value_##i##_3); \
apply (write_value_##i##_4); \
apply (remove_value_header_##i); \
} \
}
#define HANDLE_VALUE(i, ip1) \
HEADER_VALUE(i) \
PARSER_VALUE(i, ip1) \
REGISTER_VALUE(i) \
ACTION_READ_VALUE(i) \
TABLE_READ_VALUE(i) \
ACTION_ADD_VALUE_HEADER(i) \
TABLE_ADD_VALUE_HEADER(i) \
ACTION_WRITE_VALUE(i) \
TABLE_WRITE_VALUE(i) \
ACTION_REMOVE_VALUE_HEADER(i) \
TABLE_REMOVE_VALUE_HEADER(i) \
CONTROL_PROCESS_VALUE(i)
#define FINAL_PARSER(i) \
parser parse_nc_value_##i { \
return ingress; \
}
HANDLE_VALUE(1, 2)
HANDLE_VALUE(2, 3)
HANDLE_VALUE(3, 4)
HANDLE_VALUE(4, 5)
HANDLE_VALUE(5, 6)
HANDLE_VALUE(6, 7)
HANDLE_VALUE(7, 8)
HANDLE_VALUE(8, 9)
FINAL_PARSER(9)
header_type reply_read_hit_info_md_t {
fields {
ipv4_srcAddr: 32;
ipv4_dstAddr: 32;
}
}
metadata reply_read_hit_info_md_t reply_read_hit_info_md;
action reply_read_hit_before_act() {
modify_field (reply_read_hit_info_md.ipv4_srcAddr, ipv4.srcAddr);
modify_field (reply_read_hit_info_md.ipv4_dstAddr, ipv4.dstAddr);
}
table reply_read_hit_before {
actions {
reply_read_hit_before_act;
}
}
action reply_read_hit_after_act() {
modify_field (ipv4.srcAddr, reply_read_hit_info_md.ipv4_dstAddr);
modify_field (ipv4.dstAddr, reply_read_hit_info_md.ipv4_srcAddr);
modify_field (nc_hdr.op, NC_READ_REPLY);
}
table reply_read_hit_after {
actions {
reply_read_hit_after_act;
}
}
control process_value {
if (nc_hdr.op == NC_READ_REQUEST and nc_cache_md.cache_valid == 1) {
apply (reply_read_hit_before);
}
process_value_1();
process_value_2();
process_value_3();
process_value_4();
process_value_5();
process_value_6();
process_value_7();
process_value_8();
if (nc_hdr.op == NC_READ_REQUEST and nc_cache_md.cache_valid == 1) {
apply (reply_read_hit_after);
}
}
......@@ -5,7 +5,7 @@ import thread
from nc_config import *
NC_PORT = 8888
NC_PORT = 8889
CLIENT_IP = "10.0.0.1"
SERVER_IP = "10.0.0.2"
CONTROLLER_IP = "10.0.0.3"
......@@ -21,7 +21,7 @@ f.close()
kv = {}
for i in range(2, 3002, 3):
line = lines[i].split();
line = lines[i].split()
key_header = line[0]
key_body = line[1:]
val = lines[i + 1].split()
......@@ -48,7 +48,7 @@ counter = 0
def counting():
last_counter = 0
while True:
print (counter - last_counter), counter
# print (counter - last_counter), counter
last_counter = counter
time.sleep(1)
thread.start_new_thread(counting, ())
......@@ -63,20 +63,20 @@ while True:
op = struct.unpack("B", op_field)[0]
key_header = struct.unpack(">I", key_field[:4])[0]
if (op == NC_READ_REQUEST or op == NC_HOT_READ_REQUEST):
op = NC_READ_REPLY
op_field = struct.pack("B", op)
key_field, val_field = kv[key_header]
packet = op_field + key_field + val_field
s.sendto(packet, (CLIENT_IP, NC_PORT))
counter = counter + 1
elif (op == NC_UPDATE_REQUEST):
op = NC_UPDATE_REPLY
op_field = struct.pack("B", op)
key_field, val_field = kv[key_header]
packet = op_field + key_field + val_field
s.sendto(packet, (CONTROLLER_IP, NC_PORT))
print(op, key_header)
# if (op == NC_READ_REQUEST or op == NC_HOT_READ_REQUEST):
# op = NC_READ_REPLY
# op_field = struct.pack("B", op)
# key_field, val_field = kv[key_header]
# packet = op_field + key_field + val_field
# s.sendto(packet, (CLIENT_IP, NC_PORT))
# counter = counter + 1
# elif (op == NC_UPDATE_REQUEST):
# op = NC_UPDATE_REPLY
# op_field = struct.pack("B", op)
# key_field, val_field = kv[key_header]
# packet = op_field + key_field + val_field
# s.sendto(packet, (CONTROLLER_IP, NC_PORT))
#f.write(str(op) + ' ')
#f.write(str(key_header) + '\n')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment