from state import flow_emap EXP_TIME = 10 * 1000 EXT_PORT = 1 if a_packet_received: flow_emap.expire_all(now - EXP_TIME) h3 = pop_header(tcpudp, on_mismatch=([],[])) h2 = pop_header(ipv4, on_mismatch=([],[])) h1 = pop_header(ether, on_mismatch=([],[])) flow_indx = h3.dst_port - start_port if received_on_port == EXT_PORT and flow_emap.has_idx(flow_indx): internal_flow = flow_emap.get_key(flow_indx) flow_emap.refresh_idx(flow_indx, now) if (internal_flow.dip == h2.saddr and internal_flow.dp == h3.src_port and internal_flow.prot == h2.npid): return ([internal_flow.idev], [ether(h1, saddr=..., daddr=...), ipv4(h2, cksum=..., saddr=internal_flow.dip, daddr=internal_flow.sip), tcpudp(src_port=internal_flow.dp, dst_port=internal_flow.sp)]) else: pass else: # packet from the internal network pass
from state import flow_emap, int_devices EXP_TIME = 10 * 1000 EXT_DEVICE = 1 if a_packet_received: flow_emap.expire_all(now - EXP_TIME) h3 = pop_header(tcpudp, on_mismatch=([],[])) h2 = pop_header(ipv4, on_mismatch=([],[])) h1 = pop_header(ether, on_mismatch=([],[])) if received_on_port == EXT_DEVICE: internal_flow = FlowIdc(h3.dst_port, h3.src_port, h2.daddr, h2.saddr, h2.npid) if flow_emap.has(internal_flow): flow_emap.refresh_idx(flow_emap.get(internal_flow), now) else: pass else: internal_flow = FlowIdc(h3.src_port, h3.dst_port, h2.saddr, h2.daddr, h2.npid) if flow_emap.has(internal_flow): flow_emap.refresh_idx(flow_emap.get(internal_flow), now) else: pass
from state import flow_emap EXP_TIME = 10 * 1000 EXT_IP_ADDR = ext_ip EXT_PORT = 1 if a_packet_received: flow_emap.expire_all(now - EXP_TIME) h3 = pop_header(tcpudp, on_mismatch=([], [])) h2 = pop_header(ipv4, on_mismatch=([], [])) h1 = pop_header(ether, on_mismatch=([], [])) internal_flow_id = FlowIdc(h3.src_port, h3.dst_port, h2.saddr, h2.daddr, received_on_port, h2.npid) if received_on_port != EXT_PORT and flow_emap.has(internal_flow_id): idx = flow_emap.get(internal_flow_id) flow_emap.refresh_idx(idx, now) return ([EXT_PORT], [ ether(h1, saddr=..., daddr=...), ipv4(h2, cksum=..., saddr=EXT_IP_ADDR), tcpudp(h3, src_port=idx + start_port) ]) else: pass
from state import flow_emap, int_devices EXP_TIME = 10 * 1000 EXT_DEVICE = 1 if a_packet_received: flow_emap.expire_all(now - EXP_TIME) h3 = pop_header(tcpudp, on_mismatch=([], [])) h2 = pop_header(ipv4, on_mismatch=([], [])) h1 = pop_header(ether, on_mismatch=([], [])) internal_flow = FlowIdc(h3.dst_port, h3.src_port, h2.daddr, h2.saddr, h2.npid) if received_on_port == EXT_DEVICE and flow_emap.has(internal_flow): fl_id = flow_emap.get(internal_flow) flow_emap.refresh_idx(fl_id, now) out_port = vector_get(int_devices, fl_id) return ([out_port], [ether(h1, saddr=..., daddr=...), ipv4(h2, cksum=...), tcpudp(h3)]) else: pass
from state import flow_emap, flow_id_to_backend_id, backends, backend_ip_emap EXP_TIME = 10 * 1000 BACKEND_EXP_TIME = 3600000000 * 1000 EXT_PORT = 2 if a_packet_received: flow_emap.expire_all(now - EXP_TIME) backend_ip_emap.expire_all(now - BACKEND_EXP_TIME) h3 = pop_header(tcpudp, on_mismatch=([], [])) h2 = pop_header(ipv4, on_mismatch=([], [])) h1 = pop_header(ether, on_mismatch=([], [])) packet_flow = LoadBalancedFlowc(h2.saddr, h2.daddr, h3.src_port, h3.dst_port, h2.npid) if received_on_port == EXT_PORT and flow_emap.has(packet_flow): flow_id = flow_emap.get(packet_flow) backend_id = flow_id_to_backend_id.get(flow_id) if backend_ip_emap.has_idx(backend_id): flow_emap.refresh_idx(flow_emap.get(packet_flow), now) backend = backends.get(backend_id) return ([backend.nic], [ ether(h1, saddr=..., daddr=backend.mac), ipv4(h2, cksum=..., daddr=backend.ip), tcpudp(h3) ]) else: pass else: pass