25
Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open Networking Summit 2016 1

Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

Overview of Model-Driven SAL and Creating an Application based on MD-SAL

Radhika Hirannaiah, OpenDaylight Project

Open Networking Summit 2016

1

Page 2: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

Goal

• Overviewing MD-SAL internals for application development

2

Page 3: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

OpenDaylight SDN Controller

• Java-based, model-driven controller using YANG modeling language• Relies on the following technologies:

• OSGI - Back-end framework of OpenDaylight that allows dynamically loading ofbundles and packages JAR files, and binding bundles together for exchanginginformation

• Karaf - Application container built on top of OSGI, which simplifies operationalaspects of packaging and installing applications

• YANG - a data modeling language used to model configuration and state datamanipulated by the applications, remote procedure calls, and notifications

• Tools• IDE - IntelliJ IDEA or Eclipse• Java 1.7 or 1.8• Maven 3.2.3/3.3.x• Postman REST Client

3

Page 4: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

What is Model-Driven SAL(MD-SAL)?

• OpenDaylight kernel, that interfaces between different layers and modules

• Uses APIs to connect and bind requests and services

• Service Abstraction Layer (SAL) introduces an extra layer containing all the necessary logic to receive and delegate requests

• Forwards incoming requests to Service Providers (SPs) that returns service results through API to the Clients (Consumers)

4

Page 5: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

OpenDaylight Software Architecture

Controller

Model-Driven SAL (MD-SAL)

Protocol Plugin RESTCONF

NETCONF SERVER

Network Devices Applications

App/Service Plugin

App/Service Plugin

...... Protocol PluginConfig

Subsystem

Messaging Data Store

Remote Controller Instance

Remote Controller Instance

Network Applications Orchestration & Services

Controller Platform

Plugins & Applications

Clustering

Network DevicesNetwork Devices ApplicationsApplications

5

Page 6: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

Why MD-SAL?

• Evolutionary step forward from object-oriented design of network management systems

• Agnostic model that supports any device and/or service models

• Designed to stitch together the modules horizontally by allowing the developer to use generic interfaces for service discovery and consumption

• Provides “common” REST API to access data and functions defined in models

6

Page 7: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

YANG (RFC 6020)

• Modeling language that models semantics and data organization

• Models can be ‘augmented’

• Can model:• Config/Operational data as a tree

• RPCs

• Notifications

7

Page 8: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

Remote Procedure Calls (RPCs)

• Used for any call or invocation that crosses the plugin or module boundaries

• Triggered by consumers

• Communication is Unicast between consumer and provider

• Consumer sends request message to provider responding with reply message

• Models any procedure call implemented by a Provider (Server) exposing functionality to Consumers (Clients)

• Two types of RPCs –• Global – one service instance per controller container• Routed – multiple service instance per controller container

8

Page 9: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

RPCs – Sending a MessageE.g:HelloWorld application

HelloService helloService=

session.getRpcService(HelloService.class

);

Future<RpcResult<HelloWorldOutput>>

future;

future= helloService

.helloWorld(helloWorldInput);

HelloWorldOutput helloWorldOutput =

future.get().getResult();

9

consumer MD-SAL

getRpcService()

return: helloService

helloServicefuture

helloWorld(helloWorldInput)

return: future

get()

return: RpcResult<HelloWorldOutput>

set(helloOutput)

Page 10: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

Global RPCs – processing a message – Sync HelloWorld application

public class HelloWorldImpl

implements HelloService {

public HelloWorldImpl(ProviderContext

session){

session.addRpcImplementation(

HelloService.class,

this);

}

@Override

public

Future<RpcResult<HelloWorldOutput>>

helloWorld(HelloWorldInput input) {

/* construct output */

return RpcResultBuilder

.success(helloWorldOutput)

.buildFuture();

}

}

10

MD-SAL

addRpcImplementation(this)

helloWorldImpl

helloWorld(helloWorldInput)

return: future

Page 11: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

Routed RPCs – E.g:HelloWorld application

public class HelloWorldImpl1

implements HelloService {

public HelloWorldImpl(ProviderContext session){

RoutedRpcRegistration<HelloService> reg1 =

session.addRoutedRpcImplementation(

HelloService.class, this);

reg1.registerPath(MyContext.class,iid1);

}

/* helloWorld() implementation works as before */

}

public class HelloWorldImpl2

implements HelloService {

public HelloWorldImpl(ProviderContext session){

RoutedRpcRegistration<HelloService> reg2 =

session.addRoutedRpcImplementation(

HelloService.class, this);

reg2.registerPath(MyContext.class,iid2);

}

/* helloWorld() implementation works as before */

}

MD-SAL

addRoutedRpcImplementation(this)

helloWorldImpl1

helloWorld(helloWorldInput1)

return: future

reg1

return: reg2

registerPath(…)

helloWorldImpl2reg2

registerPath(…)

addRoutedRpcImplementation(this)

helloWorld(helloWorldInput2)

return: future

return: reg1

Page 12: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

RPC – OpenFlow application

• Openflowplugdin/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java

import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;

@Override

public void setRpcProviderRegistry(final RpcProviderRegistry rpcProviderRegistry) {

this.rpcProviderRegistry = rpcProviderRegistry;

}

• openflowplugin/test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginTestServiceProvider.java

RoutedRpcRegistration<SalFlowService> addRoutedRpcImplementation = ctx

.<SalFlowService> addRoutedRpcImplementation(

SalFlowService.class, this);

public RoutedRpcRegistration<SalFlowService> getFlowRegistration() {

return flowRegistration;

}

12

Page 13: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

OpenDaylight Platform

NETCONF

MD-SAL

...Flow-Capable Node Inventory Manager

Model

Statistics Manager

Model

OpenFlowTopology ExporterModel

BGP-LS Topology Exporter

Model

Data Store

• Yang data is a tree- all state-related data are modeled and represented as data tree to address any element / subtree

• Two Logical Data Stores• config• operational

• Unified View

• InstanceIdentifier:• Pointer to a node

13

p1 p2

BGP-LS

BGPv4BGPv6

nodes links prefixes

n1 n2 nx l2l1... ... lx ... px

OpenFlow

Groups

Table/1

nc:1 nc:2

/operational /config

network-topo nodes

Flow/2

of:1of:2

Of:n...

TablesMeters

Table/2Table/n

Flow/1 Flow/n...

Ports

Table-stats

Flow-statsFlow-stats

Page 14: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

Data Store Transactions• Multicast asynchronous communications, sent by Data Broker if there is change in conceptual data tree, and

is delivered to subscribed consumers

• Data Stores:• Operational Data Tree - published by the providers using MD-SAL, represents a feedback loop for applications to observe

state of the network / system.• Configuration Data Tree - populated by consumers, represents intended state of the system / network

• Transaction Types• Transactional modification to conceptual data tree - write transactions newWriteOnlyTransaction()• Transactional reads from current data tree and not affected by any subsequent write - read-only transactions

newReadOnlyTransaction()• Transaction provides both read and write capabilities – read-write transactions newReadWriteTransaction()

Modifications on Data tree:

• Put – stores a piece of data on specified path, act as add/replace• void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data);

• Merge – merges a piece of data on the existing data on specified path• void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data);

• Delete – removes the whole subtree from the specified path• void delete(LogicalDatastoreType store, InstanceIdentifier<?> path);

14

Page 15: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

Simple Data Transaction Steps

Let assume initial state of data tree for PATH is A

1. Allocates new ReadWriteTransactionReadWriteTransaction rwTx = broker.newReadWriteTransaction();

2. Read from rwTx will return value A for PATHrwRx.read(OPERATIONAL,PATH).get();

3. Writes value B to PATH using rwTxrwRx.put(OPERATIONAL,PATH,B);

4. Read will return value B for PATH, since previous write occurred in same transactionrwRx.read(OPERATIONAL,PATH).get();

5. Writes value C to PATH using rwTxrwRx.put(OPERATIONAL,PATH,C);

6. Read will return value C for PATH, since previous write occurred in same transactionrwRx.read(OPERATIONAL,PATH).get();

15

Page 16: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

Data Store – Transactions – Reading and Writing

16

ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();

Optional<Node> nodeOptional;

nodeOptional = transaction.read(

LogicalDataStore.OPERATIONAL,

n1InstanceIdentifier);

transaction.put(

LogicalDataStore.CONFIG,

n2InstanceIdentifier,

topologyNodeBuilder.build());

transaction.delete(

LogicalDataStore.CONFIG,

n3InstanceIdentifier);

CheckedFuture future;

future = transaction.submit();

n1

/operational /config

network-topo

BGPv4overlay1

nodesnodes

Datastore

n3n1

transaction

n2n3

Page 17: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

E.g: HelloWorld & OpenFlow applications

public HelloWorldImpl(DataBroker db) {

this.db = db; initializeDataTree(this.db);

}

WriteOnlyTransaction transaction = dataBroker.newWriteOnlyTransaction();

InstanceIdentifier<Node> path =

InstanceIdentifier

.create(NetworkTopology.class)

.child(Topology.class,

new TopologyKey(“overlay1”));

transaction.put(

LogicalDataStore.CONFIG,

path,

topologyBuilder.build());

CheckedFuture future;

future = transaction.submit();

openflowplugin/openflowplugin-

impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProvi

derImpl.java

@Override

public void setDataBroker(final DataBroker

dataBroker) {

this.dataBroker = dataBroker;

}

ReadWriteTransaction modification =

dataBroker.newReadWriteTransaction();

InstanceIdentifier<Group> path1 =

InstanceIdentifier.create(Nodes.class)

.child(Node.class,

testNode12.getKey()).augmentation(FlowCapableNode.class)

.child(Group.class, new GroupKey(group.getGroupId()));

modification.merge(LogicalDatastoreType.CONFIGURATION,

nodeToInstanceId(testNode12), testNode12, true);

modification.merge(LogicalDatastoreType.CONFIGURATION,

path1, group, true);

CheckedFuture<Void, TransactionCommitFailedException>

commitFuture = modification.submit();17

Page 18: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

Notifications

• Represent asynchronous events with multicast communication, published by providers for consumers

• Used to model events originating in network devices or southbound plugins that are exposed to consumers for listening

• Defined with the notification statement:notification {

….

}

• NotificationService – is a notification broker that allows clients to subscribe and publish YANG-modeled notifications

• NotificationPublishService.java - interface to publish any YANG-modeled notification which will be delivered to all subscribed listeners

18

Page 19: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

E.g. OpenFlow applicationimport

org.opendaylight.controller.md.sal.binding.api

.NotificationPublishService;

import

org.opendaylight.controller.md.sal.binding.api

.NotificationService;

@Override

public void

setNotificationProviderService(final

NotificationService

notificationProviderService) {

this.notificationProviderService =

notificationProviderService;

}

@Override

public void

setNotificationPublishService(final

NotificationPublishService

notificationPublishProviderService) {

this.notificationPublishService =

notificationPublishProviderService;

}

Openflowplugin/test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginTestCommandProvider.java

public void onSessionInitiated(final

ProviderContext session) {

notificationService =

session.getSALService(NotificationService.clas

s);

// For switch events

notificationService.registerNotificationListen

er(flowEventListener);

notificationService.registerNotificationListen

er(nodeErrorListener);

dataBroker =

session.getSALService(DataBroker.class);

ctx.registerService(CommandProvider.class.getN

ame(), this, null);

createTestFlow(createTestNode(null),

null, null);

}

19

Page 20: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

E.g. OpenFlow Pipeline Processing

20

Controller

SAL/Core

OF Inventory(Operational)

Forwarding Rules Manager

OpenFlow Java

OF Plugin

Data Change Notification

Data Store Write

OF SwitchOF SwitchOF Switch

OF Topology

Topology Manager

OF Inventory(Configuration)

NETCONF

RESTCONF

OF SwitchOF SwitchApps

RPCs/Notifications

OpenFlow 1.0/1.3

Inventory

Page 21: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

Using Futures for Logging

E.g. HelloWorld application - hello-world/impl/src/main/java/org/opendaylight/hello/impl/LoggingFuturesCallBack.javapublic class LoggingFuturesCallBack<V> implements FutureCallback<V> {

private Logger LOG;

private String message;

public LoggingFuturesCallBack(String message,Logger LOG) {

this.message = message;

this.LOG = LOG;

}

@Override

public void onFailure(Throwable e) {

LOG.warn(message,e);

}

E.g. In OpenFlow application -openflowplugin/test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowPluginBulkGroupTransactionProvider.java

Futures.addCallback(commitFuture, new FutureCallback<Void>() {

@Override

public void onSuccess(Void aVoid) {

ci.println("Status of Group Data Loaded Transaction: success.");

21

Page 22: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

Take-away: 3 Brokers

Notification Broker

publish

notify

Data Broker

notify

put

store

RPC Broker

call

22

Page 23: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

Take-away: for Application Development

• RPCs:registerToHandle( RPC, implementation )call( RPC, input ) => output

• Data Store:put( key, value )get( key ) => value

• Notifications:subscribe( notification, callback )create( notification, data )

23

Page 24: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

References

1. Controller Core Functionality Tutorials : Application Development Tutorial -https://wiki.opendaylight.org/view/Controller_Core_Functionality_Tutorials:Application_Development_Tutorial

2. Open Daylight Controller: MD-SAL -https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL

3. Developer Guide -https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL:Developer_Guide

4. YANG - RFC 6020 - https://tools.ietf.org/html/rfc6020#section-4.2.10

5. GitHub - https://github.com/opendaylight/openflowplugin

24

Page 25: Overview of Model-Driven SAL and Creating an Application ... · Overview of Model-Driven SAL and Creating an Application based on MD-SAL Radhika Hirannaiah, OpenDaylight Project Open

[email protected]

https://lists.opendaylight.org/mailman/listinfo

radhikamh at gmail dot com

25