...
코드 블럭 title FireWall // bloom 필터를 이용하여 방화벽을 구현하기 위한 함수 // apply { if (hdr.ipv4.isValid()){ ipv4_lpm.apply(); if (hdr.tcp.isValid()){ direction = 0; // default if (check_ports.apply().hit) { // test and set the bloom filter if (direction == 0) { compute_hashes(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.tcp.srcPort, hdr.tcp.dstPort); } else { compute_hashes(hdr.ipv4.dstAddr, hdr.ipv4.srcAddr, hdr.tcp.dstPort, hdr.tcp.srcPort); } // Packet comes from internal network if (direction == 0){ //호스트에서 나가는 패킷인 경우 // If there is a syn we update the bloom filter and add the entry if (hdr.tcp.syn == 1){ bloom_filter_1.write(reg_pos_one, 1); bloom_filter_2.write(reg_pos_two, 1); } } // Packet comes from outside else if (direction == 1){ //호스트에서 들어오는 패킷인 경우 // Read bloom filter cells to check if there are 1's bloom_filter_1.read(reg_val_one, reg_pos_one); bloom_filter_2.read(reg_val_two, reg_pos_two); // only allow flow to pass if both entries are set if (reg_val_one != 1 || reg_val_two != 1){ drop(); } } } } } }
2/23
- Link Monitoring
코드 블럭 title Link_Monitor // Top-level probe header, indicates how many hops this probe // packet has traversed so far. header probe_t { bit<8> hop_cnt; } // The data added to the probe by each switch at each hop. header probe_data_t { bit<1> bos; bit<7> swid; bit<8> port; bit<32> byte_cnt; time_t last_time; time_t cur_time; } // Indicates the egress port the switch should send this probe // packet out of. There is one of these headers for each hop. header probe_fwd_t { bit<8> egress_spec; } state parse_probe { packet.extract(hdr.probe); meta.parser_metadata.remaining = hdr.probe.hop_cnt + 1; transition select(hdr.probe.hop_cnt) { 0: parse_probe_fwd; default: parse_probe_data; } } state parse_probe_data { packet.extract(hdr.probe_data.next); transition select(hdr.probe_data.last.bos) { 1: parse_probe_fwd; default: parse_probe_data; } } state parse_probe_fwd { packet.extract(hdr.probe_fwd.next); meta.parser_metadata.remaining = meta.parser_metadata.remaining - 1; // extract the forwarding data meta.egress_spec = hdr.probe_fwd.last.egress_spec; transition select(meta.parser_metadata.remaining) { 0: accept; default: parse_probe_fwd; } } apply { bit<32> byte_cnt; bit<32> new_byte_cnt; time_t last_time; time_t cur_time = standard_metadata.egress_global_timestamp; // increment byte cnt for this packet's port byte_cnt_reg.read(byte_cnt, (bit<32>)standard_metadata.egress_port); byte_cnt = byte_cnt + standard_metadata.packet_length; // reset the byte count when a probe packet passes through new_byte_cnt = (hdr.probe.isValid()) ? 0 : byte_cnt; byte_cnt_reg.write((bit<32>)standard_metadata.egress_port, new_byte_cnt); if (hdr.probe.isValid()) { // fill out probe fields hdr.probe_data.push_front(1); hdr.probe_data[0].setValid(); if (hdr.probe.hop_cnt == 1) { hdr.probe_data[0].bos = 1; } else { hdr.probe_data[0].bos = 0; } // set switch ID field swid.apply(); hdr.probe_data[0].port = (bit<8>)standard_metadata.egress_port; hdr.probe_data[0].byte_cnt = byte_cnt; // read / update the last_time_reg last_time_reg.read(last_time, (bit<32>)standard_metadata.egress_port); last_time_reg.write((bit<32>)standard_metadata.egress_port, cur_time); hdr.probe_data[0].last_time = last_time; hdr.probe_data[0].cur_time = cur_time; } }