...
Tutorial에서 제공하는 예제의 토폴로지는 스위치 4개, 호스트 4개로 구성되어 있다. 그 중에 h1-h2는 s1과 연결, h3-h4는 s2와 연결 되어있는데, 이 예제에서는 s1에 p4를 이용한 스위치를 두고, bloom 방식의 firewall을 이용하여 h1,h2는 외부에 패킷을 보내 통신을 할 수 있지만, h3-h4는 h1-h2에 먼저 패킷을 보내서 통신을 할 수는 없다. 이것이 방화벽이라는 걸 알려주는 예제이다.
코드 블럭 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(); } } } } } }