Promela BCL-6 A Protocol

/*
* PROMELA Validation Model
* 协议层验证
*
* 验证BCL可靠性协议A version5.0
*
* Yuhuang
* 2007-7-26
*/

/*
* 本版本特点:采用集合点来通信,允许ACK、DATA丢包,实现了队列自动重发。
*    加入了对传输介质的模拟。介质可以丢包,导致包失序。
*
* 未完全模拟的问题:ACK、DATA失序问题
*/


/* ************* 数据结构定义 ************ */

/*  序号范围定义  */
# define WIN 9
/*
 发送队列大小定义  */
# define QSIZE 4


/*  消息类型定义  */
mtype 
=  { ACK , DATA }


/*  
 * { ACK, s_seqno }
 
*/
chan sevts 
=  [ 0 ] of { mtype ,  byte };
chan revts 
=  [ 0 ] of { mtype ,  byte };


/*
 * { DATA, r_seqno} 
 * 数据队列 
 
*/
chan sdata 
=  [ 0 ] of { mtype , byte };
chan rdata 
=  [ 0 ] of { mtype , byte };


/*  发送记录队列  */
/*  当ACK发生的时候,ACK(含)之前的内容都被清除  */
byte head_seq;
byte tail_seq;
byte cur_seq;
/*
#define inc(x) (x=(x+1)%WIN)
*/



proctype sender2media()
{
    byte seq;

    
do
    
:: sdata ? DATA , seq  ->
        
if
        
:: rdata ! DATA , seq
        
:: skip
        fi
    od
}


proctype receiver2media()
{
    byte seq;
    
do
    
:: revts ? ACK , seq  ->
        
if
        
:: sevts ! ACK , seq
        
:: skip
        fi
    od
}







proctype sender(byte id)
{

    byte s;
    
    head_seq 
=   0 ;
    tail_seq 
=   0 ;
    cur_seq 
=   0 ;
    
    
do
    
:: (tail_seq + WIN - head_seq + 1 ) % WIN  !=  QSIZE  ->      /*  队列不为满,允许发送 */
        
if
        
:: sdata ! DATA , cur_seq     /*  normal send action  */
        fi;
        
progress_2
:     cur_seq = (cur_seq + 1 ) % WIN;
        tail_seq
= (tail_seq + 1 ) % WIN;;     /*  更新tail, head保持不变  */
        
    
:: sevts ? ACK , ->     
        
/*  进行ACK失序处理  */
        
/*  若s不在当前的head_seq~tail_seq范围内,则简单忽略之  */
        
if
        
:: (head_seq  <  tail_seq)  ->      /* 顺序递增情景  */
            
if
            
:: (s  >  tail_seq  ||  s  <  head_seq )  ->
                goto endofack
            
:: else
            fi
        
:: (head_seq  >  tail_seq)  ->      /*  非递增情景  */
            
if
            
:: ( s  <  head_seq  &&  s  >  tail_seq )  ->
                goto endofack
            
:: else
            fi
        
:: else
        fi;
        
        
assert (s < WIN);
        head_seq 
=  (s  +   1 ) % WIN;     /*  根据ACK更新head_seq,暗含了累积更新  */
        cur_seq 
=  head_seq;
endofack
:     skip



    
:: ((cur_seq  !=  tail_seq)  &&  (tail_seq  -  head_seq)  !=   0  )  ->     
    
/*  队列不为空,允许发送. 此情景配合timeout时重发使用  */                                     
    
/*  第一个判断是为了防止发送不存在内容  */

        
if
        
:: sdata ! DATA , cur_seq     /*  normal send action  */
        fi;        
        cur_seq
= (cur_seq + 1 ) % WIN;        
        
    
:: timeout  ->      /*  超时  */
        
/*  更新指针,准备重发队列  */
        cur_seq 
=  head_seq;
        
/*  尝试重发队列  */
        
if
        
:: sdata ! DATA , cur_seq     /*  normal send action  */
        fi;
        cur_seq
= (cur_seq + 1 ) % WIN;     /*  发送了一个包,更新cur_seq  */
        
/*   这里不用更新tail_seq, 因为这个值只在有新的包加入到队列的时候才更新  */
    od
}


proctype receiver(byte id)
{
    byte expected_seqno;
    byte s;
    
    expected_seqno 
= 0 ;
    
    
do  
    
:: rdata ? DATA , ->
        
if
        
:: (s  !=  expected_seqno)  ->      /*  非期望数据包  */
            
if
            
:: revts ! ACK , (expected_seqno + WIN - 1 ) % WIN     /*  some acks was lost, ack again!  */
            fi
        
:: (s  ==  expected_seqno)  ->      /*  期望数据包  */
            
if
            
:: revts ! ACK , expected_seqno  ->      /*  ack  */
                expected_seqno 
=  (expected_seqno + 1 ) % WIN
            fi
        fi

    od
    
}


init
{
    atomic{
    run sender(
0 );
    run sender2media();
    run receiver(
1 );
    run receiver2media();
    }

}
 
MQTT Essentials - A Lightweight IoT Protocol by Gaston C. Hillar English | 14 Apr. 2017 | ASIN: B01MS9I105 | 280 Pages | AZW3 | 6.19 MB Key Features Make your connected devices less prone to attackers by understanding practical security mechanisms Dive deep into one of IoT's extremely lightweight machines to enable connectivity protocol with some real-world examples Learn to take advantage of the features included in MQTT for IoT and Machine-to-Machine communications with complete real-life examples Book Description This step-by-step guide will help you gain a deep understanding of the lightweight MQTT protocol. We'll begin with the specific vocabulary of MQTT and its working modes, followed by installing a Mosquitto MQTT broker. Then, you will use best practices to secure the MQTT Mosquitto broker to ensure that only authorized clients are able to publish and receive messages. Once you have secured the broker with the appropriate configuration, you will develop a solution that controls a drone with Python. Further on, you will use Python on a Raspberry Pi 3 board to process commands and Python on Intel Boards (Joule, Edison and Galileo). You will then connect to the MQTT broker, subscribe to topics, send messages, and receive messages in Python. You will also develop a solution that interacts with sensors in Java by working with MQTT messages. Moving forward, you will work with an asynchronous API with callbacks to make the sensors interact with MQTT messages. Following the same process, you will develop an iOS app with Swift 3, build a website that uses WebSockets to connect to the MQTT broker, and control home automation devices with HTML5, JavaScript code, Node.js and MQTT messages What you will learn Understand how MQTTv3.1 and v3.1.1 works in detail Install and secure a Mosquitto MQTT broker by following best practices Design and develop IoT solutions combined with mobile and web apps that use MQTT messages to communicate Explore the features included
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值