버전 비교

  • 이 줄이 추가되었습니다.
  • 이 줄이 삭제되었습니다.
  • 서식이 변경되었습니다.

...

  • Load Balancing 
    • 로드 밸런싱(Load Balancing)이란? - 수 많은 트래픽들을 처리하기 위해서 균등하게 모든 사용자에게 트래픽을 배분하여 제공해서 네트워크 과부하를 막는 기능.

    • 코드 블럭
      titleLoad Balancing
      //5 tuple에 hash알고리즘을 적용하고, 결과를 mata.ecmp_select에 저장하는 행동,
        ecmp_nhop 테이블은 이를 이용하여 전송 //
      action set_ecmp_select(bit<16> ecmp_base, bit<32> ecmp_count) {
      	hash(meta.ecmp_select,
      		HashAlgorithm.crc16,
      		ecmp_base,
      		{ hdr.ipv4.srcAddr,
      		  hdr.ipv4.dstAddr,
      		  hdr.ipv4.protocol,
      		  hdr.tcp.srcPort,
      	 	  hdr.tcp.dstPort },
      		ecmp_count);
      }
      
      // ipv4가 유효하고, ttl이 0에 도달하지 않았을 경우 전송을 실시한다. //
      apply {
      	if (hdr.ipv4.isValid() && hdr.ipv4.ttl > 0) {
      		ecmp_group.apply();
      		ecmp_nhop.apply();
      		}
      	}
      


  • QOS(Quality Of Service)
    • QOS란?

    • 코드 블럭
      titleQoS
      //트래픽 클래스에 따라 액션을 분류하여 전송할 수 있도록 여러 경우를 나누어 함수 선언//
      
      /* Default Forwarding */
      action default_forwarding() {
      hdr.ipv4.diffserv = 0;
      }
      
      
      /* Expedited Forwarding */
      action expedited_forwarding() {
      hdr.ipv4.diffserv = 46;
      }
      
      
      /* Voice Admit */
      action voice_admit() {
      hdr.ipv4.diffserv = 44;
      }
      
      
      /* Assured Forwarding */
      /* Class 1 Low drop probability */
      action af_11() {
      hdr.ipv4.diffserv = 10;
      }
      
      
      /* Class 1 Med drop probability */
      action af_12() {
      hdr.ipv4.diffserv = 12;
      }
      
      
      /* Class 1 High drop probability */
      action af_13() {
      hdr.ipv4.diffserv = 14;
      }
      
      
      /* Class 2 Low drop probability */
      action af_21() {
      hdr.ipv4.diffserv = 18;
      }
      
      
      /* Class 2 Med drop probability */
      action af_22() {
      hdr.ipv4.diffserv = 20;
      }
      
      
      /* Class 2 High drop probability */
      action af_23() {
      hdr.ipv4.diffserv = 22;
      }
      
      
      /* Class 3 Low drop probability */
      action af_31() {
      hdr.ipv4.diffserv = 26;
      }
      
      
      /* Class 3 Med drop probability */
      action af_32() {
      hdr.ipv4.diffserv = 28;
      }
      
      
      /* Class 3 High drop probability */
      action af_33() {
      hdr.ipv4.diffserv = 30;
      }
      
      
      /* Class 4 Low drop probability */
      action af_41() {
      hdr.ipv4.diffserv = 34;
      }
      
      
      /* Class 4 Med drop probability */
      action af_42() {
      hdr.ipv4.diffserv = 36;
      }
      
      
      /* Class 4 High drop probability */
      action af_43() {
      hdr.ipv4.diffserv = 38;
      }
      


2/22

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


    • 코드 블럭
      titleFireWall
      
      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

2/24


Memo

P4를 이용하기 전  무조건 알아두면 좋은 점 및 소개