Toaster Step-by-step 一步一步带你构造MD-SAL烤面包机 第一部分:定义烤面包机

该教程详细介绍了如何构建OpenDaylight Controller的MD-SAL烤面包机示例,包括定义烤面包机数据模型、实现烤面包机操作、配置数据模型以及连接服务。通过此教程,读者可以了解如何使用MD-SAL构建插件,涉及数据模型、远程过程调用、配置数据和JMX访问。
摘要由CSDN通过智能技术生成

OpenDaylight Controller:MD-SAL:Toaster Step-By-Step

1 概述

下面的教程将分解预先构建的烤面包机样本并带你从头一步一步创建烤面包机实例。我们将首先简单的定义,使访问操作数据,并推进全面的例子,演示了MD-SAL的许多方面,包括远程过程调用,通过JMXrestconf访问状态数据,通过JMX通知和消费者服务。实际上你可以按以下步骤创建新项目并执行或通过阅读和研究预先构建的代码。不管怎样,这个练习是有用的在理解一般来说你需要做些什么来从头构建MD-SAL插件。

1.1 Toaster的组成部分

     有6个部分组成这个烤面包机一步一步的例子。在这个例子中,我们说明yang模型如何为我们提供抽象,以及MD-SAL是怎样把各部分都连接起来的。

l 先决条件:定义工程结构和pom . xml文件,把我们构建的不同模块收集集合在一起。

l Part 1 Defining an Operational Toaster: 这个例子将定义烤面包机数据模型(北向接口),并将提供一个只读实现检索操作数据的烤面包机。

l Part 2 Enabling Remote Procedure Calls (RPC) - Lets make some toast!将添加并实现允许用户与操作restconf接口交互的远程过程调用,以及看到操作数据状态更改。

l Part 3 Add some configuration data - My toast is too light!第三部分说明了用户可以通过restconf修改配置数据,以及我们的烤面包机可以为这些更改侦听器。

l Part 4 Add state data to the ToasterService implementation (JMX Access) - Count my toast!这个示例将提供额外的统计属性没有出现在北向接口,但可以通过JMX实现。

l Part5 Add a consumer of the ToasterService - Let's make breakfast!将引入一个烤面包机的消费者KitchenService模型。这提供了一个演示的其他商业智能控制器可以访问的数据模型和调用RPC调用的目的提供额外的业务逻辑控制器。

l Part 6 Notifications - Oh no, the Toaster is out of bread!将扩大我们的示例通过添加主动通知从烤箱提供者和消费者通过MD-SAL路由。

2 准备烤面包机项目

文件位于:controller/opendaylight/md-sal/samples,目录文件夹应该是这样的:

1. [Root directory]

2.   pom.xml

3.   toaster

4.   toaster-config

5.   toaster-consumer

6.   toaster-provider

pom.xml定义了上级项目,并将声明上述模块的结构:

1.  <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

7.   <modelVersion>4.0.0</modelVersion>

8.  

9.   <groupId>org.opendaylight.controller.samples</groupId>

10.   <artifactId>toaster-parent</artifactId>

11.   <packaging>pom</packaging>

12.  

13.   <modules>

14.     <module>toaster</module>

15.     <module>toaster-consumer</module>

16.     <module>toaster-provider</module>

17.     <module>toaster-config</module>

18.   </modules>

19.    

20.   <scm>

21.     <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>

22.     <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>

23.     <tag>HEAD</tag>

24.     <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL</url>

25.   </scm>

26.  </project>

3 定义一个烤面包机操作

这个教程将定义烤面包机数据模型(北向接口),并将提供一个只读实现检索操作数据的烤面包机。

本系列教程的第1部分将指导您完成定义一个数据模型映射到烤面包机,并且服务提供了对给定的烤面包机操作数据。烤面包机模型和服务将由两个yang文件、一些新的和改进的java类和自动生成的java文件组成。每个yang文件为北向客户端和南向实现之间提供了另一个的抽象级别。重要的是要注意,MD-SAL提供通道而yang数据模型提供了抽象。

l toaster.yang-这个文件定义了北向数据模型。具体来说是定义了抽象烤面包机的北向可见客户端。(例如restconf API

l toaster-provider-impl.yang-这个文件定义了一个烤面包机服务的实例,这些服务来自于MD-Sal框架,例如the data-broker,这是用于存储烤面包机的操作数据。

3.1 定义烤面包机杨的数据模型

第一个yang文件toaster.yang定义了烤面包机的北向抽象数据模型,特别是属性、RPCnotifications,可以通过北向客户端进行访问。(例如restconf API).这个资源位于toaster工程的src/main/yang 文件夹下。

//这个文件包含一个yang数据定义。这个数据模型定义了一个基于SNMP MIB烤面包机例子的烤面包机。

module toaster {

  yang-version 1;//默认为1
    
  namespace
    "http://netconfcentral.org/ns/toaster";//一个独一无二命名空间,区别于其他模块的有相同的名字
  prefix toast;

  organization "Netconf Central";

  contact
    "Andy Bierman <andy@netconfcentral.org>";

  description
    "YANG version of the TOASTER-MIB.";

  revision "2009-11-20" {
    description
      "Toaster module in progress.";
  }


  identity toast-type {
    description
      "Base for all bread types supported by the toaster.
         New bread types not listed here nay be added in the 
         future.";
  }

  identity white-bread {
    base toast:toast-type;
    description "White bread.";
  }

  identity wheat-bread {
    base toast-type;
    description "Wheat bread.";
  }

  identity wonder-bread {
    base toast-type;
    description "Wonder bread.";
  }

  identity frozen-waffle {
    base toast-type;
    description "Frozen waffle.";
  }

  identity frozen-bagel {
    base toast-type;
    description "Frozen bagel.";
  }

  identity hash-brown {
    base toast-type;
    description "Hash browned potatos.";
  }

//定义类型,定义了字符长度,并对本例子使用的标准和语言版本进行了简单概述
  typedef DisplayString {
    type string {
      length "0 .. 255";
    }
    description
      "YANG version of the SMIv2 DisplayString TEXTUAL-CONVENTION.";
    reference
      "RFC 2579, section 2.";

  }

//定义了一个toaster容器,顶级配置“item”定义了一个烤面包机。‘presence’意味着只能有一个烤面包机实例,如果存在,则表明这个服务是可用的。
  container toaster {
    presence
      "Indicates the toaster service is available";
    description
      "Top-level container for all toaster database objects.";
    leaf toasterManufacturer {
      type DisplayString;
      config false;
      mandatory true;
      description
        "The name of the toaster's manufacturer. For instance, 
              Microsoft Toaster.";
    }

    leaf toasterModelNumber {
      type DisplayString;
      config false;
      mandatory true;
      description
        "The name of the toaster's model. For instance,
             Radiant Automatic.";
    }

    leaf toasterStatus {
      type enumeration {
        enum "up" {
          value 1;
          description
            "The toaster knob position is up.
                    No toast is being made now.";
        }
        enum "down" {
          value 2;
          description
            "The toaster knob position is down.
                    Toast is being made now.";
        }
      }
      config false;
      mandatory true;
      description
        "This variable indicates the current state of 
             the toaster.";
    }
    
    leaf darknessFactor {
      type uint32;
      config true;
      default 1000;
      description
        "The darkness factor. Basically, the number of ms to multiple the doneness value by.";
    }
  }  // container toaster

  

 //新增项目rpc

 rpc make-toast {
    description
      "Make some toast.
         The toastDone notification will be sent when 
         the toast is finished.
         An 'in-use' error will be returned if toast
         is already being made.
         A 'resource-denied' error will be returned 
         if the toaster service is disabled.";
    input {
      leaf toasterDoneness {
        type uint32 {
          range "1 .. 10";
        }
        default '5';
        description
          "This variable controls how well-done is the 
                 ensuing toast. It should be on a scale of 1 to 10.
                 Toast made at 10 generally is considered unfit 
                 for human consumption; toast made at 1 is warmed 
                 lightly.";
      }

      leaf toasterToastType {
        type identityref {
          base toast:toast-type;
        }
        default 'wheat-bread';
        description
          "This variable informs the toaster of the type of 
                 material that is being toasted. The toaster 
                 uses this information, combined with 
                 toasterDoneness, to compute for how 
                 long the material must be toasted to achieve 
                 the required doneness.";
      }
    }
  }  // rpc make-toast

  rpc cancel-toast {
    description
      "Stop making toast, if any is being made.
         A 'resource-denied' error will be returned 
         if the toaster service is disabled.";
  }  // rpc cancel-toast

  rpc restock-toaster {
      description
        "Restocks the toaster with the amount of bread specified.";
        
      input {
          leaf amountOfBreadToStock {
              type uint32;
              description
                "Indicates the amount of bread to re-stock";
          }
      }
  }
  
  notification toasterOutOfBread {
    description
      "Indicates that the toaster has run of out bread.";
  }  // notification toasterOutOfStock
  
  notification toasterRestocked {
    description
      "Indicates that the toaster has run of out bread.";
    leaf amountOfBread {
      type uint32;
      description
        "Indicates the amount of bread that was re-stocked";
    }
  }  // notification toasterOutOfStock
  
}  // module toaster

你可以在上面的代码中看到,在烤面包机容器内的我们标记了三个叶属性作为操作(config false,而不是配置数据。MD-SAL,随着一些IETF草案restconf配置和操作数据分割成两个独立的数据存储。

l 操作——操作性数据存储是用于显示设备的运行状态(只读)视图、网络、服务等,你可能会看。在我们的例子中我们有一个叫做烤面包机的服务可用——制造、模型和烤面包机的状态都是潜在的烤面包机和不能提供的配置(稍后我们将添加一个配置属性)。认为前两个属性是硬编码到物理设备的常量,而第三表示当前状态,和变化的烤面包机。

l 配置——配置数据存储在以某种方式通常用于配置设备。这些配置是用户,并为用户提供告诉设备如何行为。例如,如果你想以某种方式配置资源,如应用政策或其他配置,然后您将使用的数据存储。我们将添加一些本系列教程的第3部分中配置数据。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值