from twisted.internet import protocol
from twisted.application import internet, service

from opennsa import jsonrpc

PORT = 4321


def add(*args):
    return sum(args)



class JSONRPCFactory(protocol.Factory):

    protocol = jsonrpc.JSONRPCService

    def buildProtocol(self, addr):

        p = self.protocol()
        p.registerFunction('add', add)
        p.factory = self
        return p


factory = JSONRPCFactory()


application = service.Application("OpenNSA")

internet.TCPServer(PORT, factory, interface='localhost').setServiceParent(application)


#!/usr/bin/env python # syntax highlightning

from twisted.internet import protocol
from twisted.application import internet, service

from opennsa import jsonrpc, nsirouter
from opennsa.backends import dud

PORT = 4321


dud_backend = dud.DUDNSIBackend('DUD NSI Backend')
nsi_router  = nsirouter.NSIRouterAdaptor('dudnetwork', dud_backend)

class OpenNSAJSONRPCFactory(protocol.Factory):

    protocol = jsonrpc.JSONRPCService

    def buildProtocol(self, addr):

        p = self.protocol()
        p.factory = self
        jsonrpc.JSONRPCNSIServiceAdaptor(p, nsi_router)
        return p



factory = OpenNSAJSONRPCFactory()

application = service.Application("OpenNSA")

internet.TCPServer(PORT, factory, interface='localhost').setServiceParent(application)


update tac file to simple nsi service