This article describes the Packethander project, which is used to parse the packet into the controller and distribute it to different
Module for processing.
The project consists of four parts:
Config folder: Configuration information for packethander, such as plugin deployment order, configuration when initializing.
Implementation folder: The specific implementation of the service, including Java and Yang.
Model folder: Defines the packet related to Yang.
Pom.xml
First, Pom.xml
Packethander's Pom.xml file is simple and consists of two main parts:
<parent>
<groupId>org.opendaylight.l2switch</groupId>
<artifactId>l2switch-parent</artifactId>
<version>0.4.0-SNAPSHOT</version>
<relativepath>, .... /parent</relativepath>
</parent>
This configuration points to the previous parent project, stating that Packethander inherits the parent, so many configurations can be omitted.
<modules>
<module>model</module>
<module>implementation</module>
<module>config</module>
</modules>
This configuration points to the Config,implementation and model three folders, MAVEN will go to these three folders to find
Pom.xml file.
Second, model
The directory contains five Yang files and a pom.xml.
1.arp-packet.yang
The document mainly defines a grouping and a notification.
Grouping Arp-packet-fields {
Leaf XXX {
}
Leaf XXX {
}
......
Uses bpacket:packet-fields;
}
The above statement defines the structure of the ARP Pakcet.
The final uses statement will refer to grouping Packet-fields in Packet.yang.
Notification Arp-packet-received {
Uses BPACKET:PACKET-CHAIN-GRP {
Augment "Packet-chain/packet" {
Case Arp-packet {
Uses arp-packet-fields;
}
}
}
Uses bpacket:packet-payload;
}
The above statement defines a notification,notification content that is an ARP packet when provider
When a notification is submitted, all consumer that subscribe to the service receive this ARP packet.
The above statement means the introduction of the Bpacket grouping packet-chain-grp (Bpacket for Packet.yang
prefix), add a case arp-packet in the choice packet of list Packet-chain, the case
Reference to the Arp-packet-fields. Finally quoting Bpacket's grouping packet-payload, the final result
For:
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
Analysis of the above three Yang files reference 1.
5.packet.yang
The Yang file is referenced as a base file by the above 4 files.
6.pom.xml
The main function of this pom file is to compile the Yang file to generate Java code. The main parts of the statement are as follows:
<parent>
<groupId>org.opendaylight.l2switch</groupId>
<artifactId>l2switch-parent</artifactId>
<version>0.4.0-SNAPSHOT</version>
<relativepath>, .... /.. /parent</relativepath>
</parent>
inherited the parent project.
<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>
While inheriting the dependency in the parent, there is a need for some special dependencies to compile the Yang file.
<build>
<plugins>
<plugin>
......
</plugin>
<plugin>
......
</plugin>
......
</plugins>
<build>
Similarly, while inheriting the plugins in the parent, there is a need for some special plugins needed to compile the Yang file.
Third, implementation
The directory implements a specific service that contains Java files, Yang files, and pom.xml files.
1.pom.xml file
The structure of the file is similar to the previous analysis, which is no longer explained here.
2.packet-handler-impl.yang
The main part of the document:
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;
}
}
}
}
}
Register a notification service to mdsal.
3.java file
Abstractpacketdecoder.java: Defines an abstract class, the following class inherits it, and the main abstract method
Is decode, used to analyze various kinds of packet.
Arpdecoder.java: Inherits Abstractpacketdecoder, where the Decode method is used to parse the ARP packet.
Ethernetdecoder.java: Inherits the Abstractpacketdecoder, where the Decode method is used to parse the Ethernet frame.
Ipv4decoder.java: Inherits Abstractpacketdecoder, where the Decode method is used to parse IPV4 packets.
Ipv6decoder.java: Inherits Abstractpacketdecoder, where the Decode method is used to parse Ipv6 packets.
Iv. Config
Mainly contains an XML configuration file: 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>
It creates an initial configuration for Packethandler, primarily registering the notification service in Mdsal, at run time,
The actual module instance is inserted below the modules/module/.
Finally if the description of the file name in the 50, the number represents the start level, the higher the number, the lower the priority of the boot, such as the mdsal of 1,
is started first.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.