opendaylight(Li) l2switch 原始碼分析(3)--packethandler

來源:互聯網
上載者:User
本文介紹packethander工程,該工程用於對進入到controller的packet進行解析並分發到不同的
模組進行處理。
工程分為四個部分:
config檔案夾:packethander的配置資訊,如plugin的部署順序,初始化時的配置。
implementation檔案夾:service的具體實現,包含了java和yang。
model檔案夾:定義了packet相關的yang。
pom.xml


一、pom.xml
packethander的pom.xml檔案很簡單,主要包含一下兩部分:
  <parent>
    <groupId>org.opendaylight.l2switch</groupId>
    <artifactId>l2switch-parent</artifactId>
    <version>0.4.0-SNAPSHOT</version>
    <relativePath>../parent</relativePath>
  </parent>
該配置指向了之前講的parent工程,說明packethander繼承了parent,所以很多配置都可以省略。

  <modules>
    <module>model</module>
    <module>implementation</module>
    <module>config</module>
  </modules>
該配置指向了config,implementation和model三個檔案夾,maven會去這三個檔案夾下面去找
pom.xml檔案。


二、model
該目錄包含了五個yang檔案和一個pom.xml.

1.arp-packet.yang
該檔案主要定義了一個grouping和一個notification。
grouping arp-packet-fields {
leaf xxx {
}

leaf xxx {
}
......
uses bpacket:packet-fields;
}
上面的語句定義了arp pakcet的結構。
最後的uses語句會引用packet.yang中grouping packet-fields。

notification arp-packet-received {
  uses bpacket:packet-chain-grp {
    augment "packet-chain/packet" {
       case arp-packet {
        uses arp-packet-fields;
      }
    }
  }
  uses bpacket:packet-payload;
}
上面的語句定義了一個notification,notification的內容是一個arp packet,當Provider
提交一個notification時,所有的訂閱該服務的Consumer都會收到這個arp packet.

上述語句的意思是引入了bpacket的grouping packet-chain-grp(bpacket為packet.yang
的prefix),在list packet-chain的choice packet中增加一個case arp-packet,該case
引用了arp-packet-fields。最後引用bpacket的grouping packet-payload,最終的結果
為:
notification arp-packet-received {
    list packet-chain {
      choice packet {
        case arp-packet {
          uses arp-packet-fields;
        }
        case raw-packet {
          uses raw-packet-fields;
        }
      }
    }
    grouping packet-payload {
      leaf payload {
        type binary;
      }
    }
}

2.ethernet-packet.yang
3.ipv4-packet.yang
4.ipv6-packet.yang
上面三個YANG檔案的分析參考1。

5.packet.yang
該YANG檔案作為一個基礎檔案被上面4個檔案引用。

6.pom.xml
這個pom檔案主要作用是編譯yang檔案產生java代碼。主要的幾部分語句如下:
<parent>
    <groupId>org.opendaylight.l2switch</groupId>
    <artifactId>l2switch-parent</artifactId>
    <version>0.4.0-SNAPSHOT</version>
    <relativePath>../../parent</relativePath>
</parent>
繼承了parent工程。

  <dependencies>
    <dependency>
      <groupId>org.opendaylight.openflowplugin.model</groupId>
      <artifactId>model-flow-service</artifactId>
    </dependency>
    <dependency>
      <groupId>org.opendaylight.mdsal.model</groupId>
      <artifactId>ietf-yang-types</artifactId>
    </dependency>
  </dependencies>
雖然繼承了parent中的依賴關係,這邊還需要一些編譯yang檔案所需的特別的依賴。

<build>
    <plugins>
      <plugin>
    ......
      </plugin>    
      <plugin>
    ......
      </plugin>    
    ......
     </plugins>
<build>
同樣,雖然繼承了parent中的外掛程式,這邊還需要一些編譯yang檔案所需要的特別的外掛程式。


三、implementation
該目錄實現了具體的service,包含了java檔案,yang檔案和pom.xml檔案。

1.pom.xml檔案
該檔案的的結構和之前分析的差不多,這邊就不再說明了。


2.packet-handler-impl.yang
該檔案的主要部分:
  augment "/config:modules/config:module/config:configuration" {
    case packet-handler-impl {
      when "/config:modules/config:module/config:type = 'packet-handler-impl'";

      container notification-service {
        uses config:service-ref {
          refine type {
            mandatory true;
            config:required-identity mdsal:binding-notification-service;
          }
        }
      }
    }
  }
註冊一個notification service到mdsal中。


3.java檔案
AbstractPacketDecoder.java:定義了一個抽象類別,下面的類都會繼承它,主要抽象方法
是decode,用於解析各類packet。
ArpDecoder.java:繼承AbstractPacketDecoder,其中的decode方法用於解析arp包。
EthernetDecoder.java:繼承AbstractPacketDecoder,其中的decode方法用於解析乙太網路幀。
Ipv4Decoder.java:繼承AbstractPacketDecoder,其中的decode方法用於解析Ipv4資料包。
Ipv6Decoder.java:繼承AbstractPacketDecoder,其中的decode方法用於解析Ipv6資料包。


四、config
主要包含一個xml設定檔:50-packethandler.xml
  <configuration>
    <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
      <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
        <module>
          <type xmlns:prefix="urn:opendaylight:packet:packet-handler-impl">
            prefix:packet-handler-impl
          </type>
          <name>packet-handler-impl</name>

          <notification-service>
            <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">
              binding:binding-notification-service
            </type>
            <name>binding-notification-broker</name>
          </notification-service>
        </module>
      </modules>
    </data>
  </configuration>
它為packethandler建立了初始配置,主要是在mdsal中註冊notification service,在運行時,
實際的模組執行個體會被插入到modules/module/下面。

最後要是說明下檔案名稱中的50,該數字代表了啟動等級,數字越高,啟動的優先順序越低,比如mdsal的為1,
則最先啟動。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.