...
코드 블럭 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--------------------------------------------------------------------------------------------------------- // 패킷을 받고 스위치에서 패킷을 분석 할때 헤더에 따라서 행해야 하는 행동을 지시하는 Parser부분에 추가한 // 헤더들에 맞게 상태 함수를 추가하여준다. state parse_probe { 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; } } // 최상위 프로브 헤더 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대한 forbit의 this packet's portcnt 증가 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; } }
...