You are on page 1of 5

Modeling and Simulation of CAN Network Based on OPNET

Jia Hao

Jiechang Wu

Department of Mechanical Engineering


Naval University of Engineering
Wuhan, China
472497914@qq.com

Department of Mechanical Engineering


Naval University of Engineering
Wuhan, China
wujiechang1234@163.com
Chaoyou Guo

Department of Mechanical Engineering


Naval University of Engineering
Wuhan, China
haojia526@yahoo.com.cn
OPNET, one of the network simulation software widely
employed in modeling and simulation of communication
networks, has distinct advantage in model design, data
collection and data analysis. OPNET adopts hierarchical
modeling mechanism which contains network layer, node
layer and process layer, naturally paralleling the structure of
actual communication networks, and performs discrete
event simulation to analyze both behavior and performance
of modeled systems. In the description of process model the
Finite State Machine model which always used to describe
communication protocol is adopted and a flexible, high-level
programming language is provided which allows realistic
modeling most of all communications protocols, algorithms,
and transmission technologies [4]-[5]. Consequently, this
paper establishes the CAN bus network model using OPNET
Modeler, the models of Logical Link Control and Medium
Access Control are established hierarchically according the
CAN bus protocol, and the CAN bus physical layer model is
also designed and implemented; lastly, this paper describes
the behavior of CAN bus communication and the
mechanism of both collision detection and non-destructive
arbitration, then analyzes the CAN bus protocol and
network performance and offers some helpful reference
about the CAN Bus network optimization design through
research on typical network.

Ahstract-To analyze controller area network protocol and

evaluate CAN network performance, this paper provides a way


in which the Layered modeling method is adopted to build the
CAN

network model

in

the

OPNET

Modeler

simulation

environment. The models of Logical Link Control and Medium


Access Control of CAN protocol with the functions of error
handling and channel status detection were established in the
OPNET node Layer; and the model of CAN bus physical layer
was

designed

to

implement

collision

detection

and

non

destructive arbitration functionality in the OPNET Pipeline


Stages. A case model was simulated in a specifically network
environment, through analyze the simulation result, a research
was made into the CAN bus performance such as End-to-End
delay and throughput. These results show that the OPNET
model can effectively describe and analyze the communication
behavior of CAN bus, and set up a good basis for further
design and realization of communication protocols.
Keywords-controller

area

network;

OPNET;

modeling;

simulation; optimization design; Layered modeling method

I.

INTRODUCTION

The CAN protocol implements a priority-based bus,


with a carrier sense multiple access with collision avoidance
(CSMAlCA) MAC, which has such merits as high baud rate,
reliably function, convenient debugging, good flexibility
and high cost-effective, therefore, it has been widely used in
industrial automation field in recent years [1]. The real-time
communication performance of CAN Bus deserves to be
primarily concerned in the development of Measure and
Control system based-on CAN Bus. In the research, the
algorithm for dynamic scheduling of real-time tasks such as
RM or EDF and formal model of CAN protocol with
application of statistics are widely used. Petri Net, Finite
State Machine and State Chart are traditionally used for
behavior modeling [2]. The best feature of the model based
on Petri Net is intuitionistic, and the performance of Petri
Net model can be analyzed with reachability tree,
reachability graph and state equation, but simulation tools
cannot be act for when the scale of the network is large;
however simulation tools for Petri Net such as OPMSE,
VPNT have the defection in mathematics ability [3].

II.

THE CAN PROTOCOL AND MODELING METHODS


BASED ON

A.

OPNET

The communication mechanism of CAN Bus protocol

CAN Bus agreement conforms to standard OSI reference


model, which is divided into physical layer and data link
layer which consists of LLC layer and MAC layer, and MAC
layer is the core of CAN Bus protocol. CAN Bus
performance depend crucially on MAC layer protocol whose
communication process can be described briefly as: the
nodes in CAN detect the Bus state before attempting to send
message. When the Bus becomes idle, every node with
pending messages will start to transmit. When there is a
collision because that two or more nodes start to transmit at
the same time, Nondestructive Arbitrator Mechanism is

978-1-61284-486-2/111$26.00 2011 IEEE

577

functions that CAN bus Physical Layer need to


realization [4]-[6].

applied. With the aid of identifier and bit-by-bit arbitration


rules, the transmission of low-priority message is aborted,
and the highest-priority message being transmitted will
proceed without perceiving any collision and, thus, will be
successfully transmitted, without losing information and time.
CRC checkout is used to cany out checkout of data during
transportation, the node releases bus after accomplishing data
communication [1], its flow chart is shown in Fig. 1.

III.
A.

B.

The network layer model of CAN bus

CAN bus is particularly suited to build distributed


monitoring and controlling networks as a field bus which is
widely applied in industrial process control filed,
consequently, the network topology of CAN bus is
configured to be master-slave mode network in the network
layer modeling of CAN bus in this paper, the model is
shown in Fig. 2.

Start

Figure 1.

THE DESIGN OF CAN BUS PROTOCOL MODEL

The Communication Mechanism of MAC Layer Protocol

OPNET Modeling method for CAN bus protocol

During the establishment of CAN bus protocol model,


OPNET divides the Design Model into three layers that are
network model, node model and process model using the
Layered Modeling Techniques and Object-oriented
Software Technology, and completes the designs of three
aspects function modules of CAN bus including network
topology, internal constitution of node and communication
behaviors. On the basis, the OPNET model of CAN bus
protocol is established in this paper with the methods
described below:

In the network model design, the configuration of


network topology and the design of link model are
implemented using the methods of model
deployment and data description;

Based on the communication principles of layered


protocol in the node model design, the designs of
each protocol module and physical resources of
CAN protocol such as Application Layer, Data Link
Layer and Physical Layer are completed using
processor module, queue module and transceiver
module in OPNET, and the communication interface
between each protocol module is defmed by Packet
Stream, Statistic Wire and Interface Control
Information;

The design of process model is based on Finite State


Machine Mechanism, in which the process model of
each layer protocol module of CAN bus is described
by Proto-C Language (a C language based on FSM)
and Lib Functions which is provided specially for
protocol design. A large portion of protocol standard,
algorithm and queue strategy of CAN bus can be
implemented in process model;

The design of CAN bus Physical Layer can be


finished in the link model, and the attribute and
interface are defined according to the primary

Figure 2.

B.

The Network Layer Model of CAN Bus

The node layer model of CAN bus

According to the communication principles of protocol


layer, the node layer model is divided into three layers
network that are Application Layer, Data Link Layer and
Physical Layer from top to bottom, communication
mechanism of packet stream is used between each layers, as
shown in Fig.3.

Figure 3.

The Node Layer Model of CAN Bus

In Fig.3, the modules of data source (source) and data


sink (sink) form a simplest Application Layer, that are
responsible for data generation and destruction; Data Link
Layer consists of can_lIc module, can_mac module and
deference module, among which can_mac module
implements the function of MAC layer, with responsibility
for data encapsulation/decapsulation, media access manage
and error detection. The interface function between

578

nodes sending data at the same time in transmIssIOn, the


process model then enters into COLL_WAIT state beginning
to arbitrate priority. If the current node has a high priority,
the process model then turns into TRANFER state
continuing to transmit data without infection. When the
transmission is completed and current node is acknowledged,
the process model enters into FRM_END state showing that
the data transmission is finished; otherwise, if the current
node has a low priority, the process model then turns into
DEF_WAIT state waiting until after the high priority nodes
finish transmission, then it enters into TX_START state
transmitting the data afresh. If there is a error find during
the transmission, the process model immediate halts of the
data transmission and enters into ERR WAIT state
beginning to send error frame, and the value of the transmit
error register increases 8; otherwise there is no error find,
the value of the transmit error register decreases 1.
The data from Physical Layer can be received in the
states of WAIT, DEF_WAIT, TXEV_WAIT, ACK_WAIT and
TRANFER, and the data is received if its identifier in
agreement with the acceptance filters of the current node. If
there is a error find during the reception, the value of the
receive error register increases 8, and the process model
enters into ERR_WAIT state beginning to send error frame,
otherwise there is no error find, the value of the receive
error register decreases 1.
The realization of the priority arbitrator mechanism
arithmetic can be described as: Every node marks itself with
a flag called "competes bus" during the transmission, when
there is a collision occurred due to several nodes sending
data at the same time, each node of conflict reads the
information of all the nodes which link to bus, then the
current node is compared with all the other nodes one by
one, when detecting a high priority node, the number_high
increases 1. After the comparison is finished, if
number_high equals to 0, it means that the current node has
the highest priority, and the transmission can be continue;
otherwise the transmission aborted. The realization of the
priority arbitrator mechanism arithmetic in OPNET can be
seen below in Fig.5.

Application Layer and MAC is implemented by can_llc


module, and the detection of channel status is carried out by
deference module; rx and tx modules are respectively bus
receiver and transmitter, which constitute the Physical Layer
of CAN bus.
C.

The process layer model of CAN bus

The operational mechanism of CAN bus is chiefly


implemented in MAC layer, and in order to avoid timing
disorder due to complex model in a single module, in this
paper MAC model is divided into two independent function
modules that are can_mac module and deference module,
which can realize MAC layer function together through the
communication of Statistic Wire, the process model of
can_mac is shown in Fig.4.
1) The model design of the MAC protocol of CAN bus
can_mac process model includes three communication
behaviors that are data transmitting, data receiving and error
handling. Based on the MAC protocol of CAN Bus and the
Modeling Methods of OPNET, the process model of
can mac is built in this paper can be seen below in Fig.4.

num node=
op_topo_object_count(OPC_OBJTYPE_NODE]IX);
op_ima_obLattret(own_node_objid,"can_llc.can_identifi
er",&my_node_can_id);
for(i = 0; i<num_node;i++)
Figure 4.

The Process Model of

can_mac

node_objid =
op_topo_child(sub_objid,OPC_OBJTYPE_NODE]IX,i);
op_ima_obLattret(node_objid,"can_mac.tran_id",&tran
_status);
if(tran_status == 1)

In Fig.4, the initial state of the process model is in INIT


state in which statistics needed to gather in simulation is
registered and initialized, after finishing this, the process
model enters into WAIT state waiting for the arrival of data
from Application Layer. In TX_JAM state, the new arrived
data is inserted into transmit buffer, if the transmit buffer is
not empty the process model then enters into FRM_START
state detecting bus state before transmitting data. When
CAN Bus is busy, the process model turns into DET_WAIT
state and it will not enters into TX START state until bus
becomes idle, in this state, the data in transmit buffer is sent
on to bus, if there is a collision occurred due to several

op_ima_obLattret(node_objid,"can_llc.can_identi
fier",&other_node_can_id);
if(other_node_can_id < my_node_can_id)
number _high=number_high+ 1;

Figure 5.

579

The Priority Arbitrator Mechanism Arithmetic

The realization of the error handling mechanism can be


described as: The Error Flag has to do with the fault state of
each node being in, as shown in Fig.6, when error occurs,
the node first make sure which state it being in. If either of
the value of receive error register or transmit error register is
less than 127, it shows that the node is in error active state,
then error active flag is sent; or if either of the value of
receive error register or transmit error register is greater than
127, which shows that the node is in error passive state, then
error passive flag is sent; otherwise, if the value of receive
error register is greater than 255, the bus is off, and it will
not becomes on until there is 128 successive occurrences of
11 recessive bits.

waiting for a time of frame space (in SPACING state). The


process model of deference is shown in Fig.7.

Figure 7.

D.

Figure 6.

Error Frame includes two parts: Error Flag and Error


Delimiter. Error Flag finally on bus is formed by the Error
Flags of different nodes superposition, its length ranges
from 6 to 12 bits, and the length of Error Delimiter is 8 bits,
thus, in the worst case, the Error Frame sent on to bus in the
error active state will up to 20 bits long; and which is sent in
the error passive state still includes a time interval called
"Suspend Transmission", its length is 8 bits, thus, the error
frame sent in the error passive state will up to 28 bits long
[5]. The time delay formula caused by Error Frame can be
evaluated as follows:

2)

TErrorActive

TErrorPassi ve

-x

The Link model of CAN bus

Ttxdelay

(12 + 8)

(1)
X

(20 + 8)

Ix

The channel model design of CAN bus

The channel model of CAN bus is described by


deference process model, and in deference process model

the channel is unoccupied at the beginning, it can be defined


in DEF OFF state. The model will enters into FRM WAIT
state if there have a data frame waiting for transmitting, and
it wills not turn into DEF ON state until the data frame is
sent on to bus. In DEF_ON state, the value of the statistic is
revised, and informs all the nodes of that the bus is occupied,
then the model enters into FREE_WAlI state, it wills not
return into DEF OFF state until the bus becomes idle and
-

-xpk1enbit

(2)

Vtx

vtx
-

deference

A link's underlying implementation can generally be


thought of as a sequentially executed set of pipeline stages
which are composed of a series of C or C++ language
procedures, and when a packet is sent to a transmitter, the
Simulation Kernel of OPNET to call appropriate pipeline
stages procedures to process the packet [7]. The link model
of CAN bus can be defined by transceiver pipeline, the
User-Defined link model of CAN bus is built by revising
pipeline stages procedures in this paper.
The pipeline of CAN bus link model consists of six
stages that are Transmission Delay, Link Closure,
Propagation Delay, Collision, Error Allocation and Error
Correction. This paper builds the link model through
revising the procedures of first three stages.

Transmission Delay: This time delay is computed


independently for each new packet transmission, and
represents the simulated time interval which the
transmitter requires to completely process and
transmit the packet. In this model, letting baud rate
be Vtx and supposing that the length of data packet is
pklenbib so the Transmission Delay can be evaluated
as follows:

Fault State Transition Diagram

The Process Model of

580

Link Closure: Closure is computed independently for


each bus receiver which is attached to the bus; it
represents the ability of the transmitter to reach a
specific bus receiver. In this model, supposing that
every transmitter can reach every bus receiver,
namely, every node can communicate with each
other.
Propagation Delay: It is caused by the distance
between transmitter and receiver, in this model the
effect of distance on End-to-End delay is ignored,
therefore, the distance among all the nodes is
assumed to be O.

high priority if the packet it sent is importance; Fig.8 (b)


shows that throughput (S) will increases with the decreases
of the data sending period, consequently, if the data sending
period effect on network performance does not considered,
the data sending period can be reduced to increase the
throughput (S).

THE ANALYSE AND SIMULATION OF THE NETWORK


PERFORMANCE OF CAN Bus

IV.

The CAN network model based on OPNET is simulated


in this section, and the network performance is analyzed
through simulation results. This paper mainly considers the
effects of node priority and data sending period on CAN
network performance.
The CAN network model established in this paper adopts
master-slave structure; each slave node (slave_I-slave_4)
can receives the packet transmitted from the master node
(master), and every slave node has the equal chances to send
packet to the master node. In the configuration of the
simulation environment, the data transport rate of network is
set to 1Mbps, the data sending period yields to random
Poisson distribution with mean A, and the idiographic setting
of node priority, packet length and the mean A of sending
period in different scenario are shown in Table I.

Figure 9.

THE NETWORK CONFIGURE OF CAN Bus IN OPNET

TABLE!.

Node

PRI

Packet
Length
Ibit

master
slave I
slave 2
slave 3
slave 4

0
I
2
3
4

44-108

the mean A of Sending Period/sec


scenariol

scenario2

scenario3

20

80

The Relationship Between ETE_delay and PRI

Fig.9 shows that End-to-End delay (ETE_delay)


increases with the decreases of the priority of node, it shows
that when the collision occurred, the Priority Arbitrator
Mechanism of CAN bus permits the node with high priority
to keep on transmitting packet, and the nodes with low
priority take initiative to quit transmission, therefore, a node
should be set to high priority if it has the high demand on
Real-time.

The results for throughput (S) and End-to-End delay


(ETE_delay) are obtained by executing the model under
OPNET Modeler, as shown in Fig. 8 and Fig. 9, respectively.

V.

CONCLUSION

The paper constructs the CAN network model based on


OPNET Modeler, and the network model, node model,
process model and link model are designed and realized, then
the performance of CAN bus is analyzed by simulating the
model. The model established in this paper reflects the
characteristic of CAN protocol in truth and which can be
used in various research with the powerful generality.
REFERENCES

Figure 8.

The Relationship Among througput, PRI and A

Fig.8 (a) shows that throughput (S) increases greatly as


the priority of node increased in the nodes with different
priority, it gives the facts that the node with high priority has
the high probability of successful packet transmission, and
has the low probability of loss of data, so a node can be set to

581

[I]

L M.Pinho, F. Vasques, and E. Tovar, "Integrating Inaccessibility in


Response Time Analysis of CAN Networks," Proc. 2000 Proceedings
of Factory Communication Systems, IEEE Press, 2000,pp.77-84.

[2]

Yue ZHOU, Haibin YU, Tainran WANG, and Chengdong WV,


"DSPN modeling and performance analysis of CSMNCA
communication for CAN," Chinese Journal of Scientific Instrument.
vol.27, Sep. 2006, pp.991-995.

[3]

Jiping TAO, Wenyan XU, Genke YANG, and Hao WANG, "A
Simulation Method of Petri Nets Based on Stateflow," COMPUTER
SIMULATION. vol.23, Dec. 2006, pp.96-113.

[4]

Xin LI, Ming YE, and Wenhua HAO, "Network Modeling and
Simulation with OPNET Modeler," XIDIAN UNIVERSITY
press.2006,pp. l -9.

[5]

Xiaoting LI, Fan DING, and Huagang XIONG, "CAN modeling and
simulation based on OPNET," Journal of Beijing University of
Aeronautics and Astronautics, vo1.35, Mar. 2009, pp.284-287.

[6]

Haihong CHEN, "Analysis of OPNET simulation technology,"


Journal of Chifeng University. vol 26, May.2010, pp.23-24.

[7]

Song GUO, "Declassified of Modeling and Simulation with OPNET


Modeler," Publishing House of Electronics Industry. 2010,pp.26-30.

You might also like