Example #1
0
    def NFDStrategyList(self, request, context):
        cmd = "nfdc strategy list"
        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        output_all = ps.communicate()[0]

        ack_reply = nfd_agent_pb2.AckReply()
        if is_error(output_all):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = ('%s' % output_all)
            return nfd_agent_pb2.NFDStrategyListRes(strategies=[],
                                                    ack=ack_reply)
        else:
            ack_reply.ack_code = 'ok'

        strategies = []
        output_list = output_all.split("\n")
        for one_line in output_list:
            if not one_line or one_line == '': continue
            strategies.append(one_line)

        return nfd_agent_pb2.NFDStrategyListRes(strategies=strategies,
                                                ack=ack_reply)
Example #2
0
    def NFDStrategyUnset(self, request, context):
        # nfdc strategy unset prefix <PREFIX>
        # nfdc strategy set prefix /localhost
        cmd = "nfdc strategy unset"
        if request.prefix:
            cmd += (" prefix %s" % request.prefix)

        ack_reply = nfd_agent_pb2.AckReply()
        if len(cmd) <= len('nfdc strategy unset'):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = 'subcommand is not set'
            return ack_reply

        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        output_all = ps.communicate()[0]
        if is_error(output_all):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = ('%s' % output_all)
        else:
            ack_reply.ack_code = 'ok'
            ack_reply.ack_msg = ('%s' % output_all)
        return ack_reply
Example #3
0
    def NFDStrategyShow(self, request, context):
        cmd = "nfdc strategy show"
        if request.prefix:
            cmd += (" prefix %s" % request.prefix)

        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        output_all = ps.communicate()[0]

        ack_reply = nfd_agent_pb2.AckReply()
        if is_error(output_all):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = ('%s' % output_all)
            return nfd_agent_pb2.NFDStrategyShowRes(strategy='', ack=ack_reply)
        else:
            ack_reply.ack_code = 'ok'

        # delete last \n character
        if output_all.rindex('\n') > 0:
            output_all = output_all[::-1].replace('\n', '', 1)[::-1]

        return nfd_agent_pb2.NFDStrategyShowRes(strategy=output_all,
                                                ack=ack_reply)
Example #4
0
    def NFDRouteRemove(self, request, context):
        # nfdc route remove prefix <PREFIX> nexthop <FACEID|FACEURI> [origin <ORIGIN>]
        # nfdc route remove prefix /localhost/nfd nexthop 257
        # nfdc route remove prefix /localhost/nfd nexthop udp://192.168.123.123
        # nfdc route remove prefix /localhost/nfd nexthop 257 origin static
        cmd = "nfdc route remove"
        if request.prefix:
            cmd += (" prefix %s" % request.prefix)
        if request.nexthop:
            cmd += (" nexthop %s" % request.nexthop)
        if request.origin:
            cmd += (" origin %s" % request.origin)

        ack_reply = nfd_agent_pb2.AckReply()
        if len(cmd) <= len('nfdc route remove'):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = 'subcommand is not set'
            return ack_reply

        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        output_all = ps.communicate()[0]

        if is_error(output_all):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = ('%s' % output_all)
        else:
            ack_reply.ack_code = 'ok'
            ack_reply.ack_msg = ('%s' % output_all)

        return ack_reply
Example #5
0
    def NFDStatusReport(self, request, context):
        cmd = "nfdc status report"
        if request.format:
            cmd += (" format %s" % request.format)

        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        output_all = ps.communicate()[0]

        ack_reply = nfd_agent_pb2.AckReply()
        if is_error(output_all):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = ('%s' % output_all)
            return nfd_agent_pb2.NFDStatusReportRes(report='', ack=ack_reply)
        else:
            ack_reply.ack_code = 'ok'

        # delete last \n character
        if request.format == 'text':
            if output_all.rindex('\n') > 0:
                output_all = output_all[::-1].replace('\n', '', 1)[::-1]

        return nfd_agent_pb2.NFDStatusReportRes(report=output_all,
                                                ack=ack_reply)
Example #6
0
    def NFDRouteShow(self, request, context):
        # Get Face List
        cmd = "nfdc route show"
        if request.prefix:
            cmd += (" prefix %s" % request.prefix)

        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        output_all = ps.communicate()[0]

        ack_reply = nfd_agent_pb2.AckReply()
        if is_error(output_all):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = ('%s' % output_all)
            return nfd_agent_pb2.NFDRouteShowRes(route=[], ack=ack_reply)
        else:
            ack_reply.ack_code = 'ok'

        route = []
        output_list = output_all.split("\n")
        for one_line in output_list:
            if not one_line or one_line == '': continue
            route.append(one_line)

        return nfd_agent_pb2.NFDRouteShowRes(route=route, ack=ack_reply)
Example #7
0
    def NFDRouteAdd(self, request, context):
        # nfdc route add prefix <PREFIX> nexthop <FACEID|FACEURI> [origin <ORIGIN>] [cost <COST>] [expires <EXPIRATION-MILLIS>]
        # nfdc route add prefix /localhost/nfd nexthop 257
        # nfdc route add prefix /localhost/nfd nexthop udp://192.168.123.123
        # nfdc route add prefix /localhost/nfd nexthop 257 cost 100
        cmd = "nfdc route add"
        if request.prefix:
            cmd += (" prefix %s" % request.prefix)
        if request.nexthop:
            cmd += (" nexthop %s" % request.nexthop)
        if request.origin:
            cmd += (" origin %s" % request.origin)
        if request.cost:
            cmd += (" cost %s" % request.cost)
        if request.expires:
            cmd += (" expires %s" % request.expires)

        ack_reply = nfd_agent_pb2.AckReply()
        if len(cmd) <= len('nfdc route add'):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = 'subcommand is not set'
            return ack_reply

        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        output_all = ps.communicate()[0]
        if is_error(output_all):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = ('%s' % output_all)
        else:
            ack_reply.ack_code = 'ok'
            ack_reply.ack_msg = ('%s' % output_all)
        return ack_reply
Example #8
0
    def NFDFibList(self, request, context):
        # Get Face List
        cmd = "nfdc fib list"
        if request.faceid > 0:
            cmd += (" | grep faceid=%s" % request.faceid)
        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        output_all = ps.communicate()[0]

        ack_reply = nfd_agent_pb2.AckReply()
        if is_error(output_all):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = ('%s' % output_all)
            return nfd_agent_pb2.NFDFibListRes(fib=[], ack=ack_reply)
        else:
            ack_reply.ack_code = 'ok'

        fib = []
        output_list = output_all.split("\n")
        for one_line in output_list:
            if not one_line or 'FIB:' in one_line: continue
            one_line = re.sub('^  /', '/', one_line)
            fib.append(one_line)

        return nfd_agent_pb2.NFDFibListRes(fib=fib, ack=ack_reply)
Example #9
0
    def NFDRouteList(self, request, context):
        cmd = "nfdc route list"
        if request.nexthop and request.nexthop != '0':
            cmd += (" nexthop %s" % request.nexthop)
        if request.origin:
            cmd += (" origin %s" % request.origin)

        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        output_all = ps.communicate()[0]

        ack_reply = nfd_agent_pb2.AckReply()
        if is_error(output_all):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = ('%s' % output_all)
            return nfd_agent_pb2.NFDRouteListRes(route=[], ack=ack_reply)
        else:
            ack_reply.ack_code = 'ok'

        route = []
        output_list = output_all.split("\n")
        for one_line in output_list:
            if not one_line or one_line == '': continue
            route.append(one_line)

        return nfd_agent_pb2.NFDRouteListRes(route=route, ack=ack_reply)
Example #10
0
    def NFDFaceDestroy(self, request, context):
        # nfdc face destroy [faceid]
        # Get Face List
        cmd = "nfdc face destroy"
        if request.faceid:
            cmd += (" %s" % request.faceid)

        ack_reply = nfd_agent_pb2.AckReply()
        if len(cmd) <= len('nfdc face destroy'):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = 'faceid parameter is not set'
            return ack_reply

        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        output_all = ps.communicate()[0]

        if is_error(output_all):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = ('%s' % output_all)
        else:
            ack_reply.ack_code = 'ok'
            ack_reply.ack_msg = ('%s' % output_all)

        return ack_reply
Example #11
0
    def NLSRLsdbList(self, request, context):
        # Get Face List
        cmd = "nlsrc lsdb"
        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        output_all = ps.communicate()[0]

        ack_reply = nfd_agent_pb2.AckReply()
        if is_error(output_all):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = ('%s' % output_all)
            return nfd_agent_pb2.NLSRLsdbListRes(lsdb=[], ack=ack_reply)
        else:
            ack_reply.ack_code = 'ok'

        lsdbs = []
        output_list = output_all.split("\n")
        origin_router = ''
        for one_line in output_list:
            if 'OriginRouter: ' in one_line:
                if origin_router == '' or origin_router not in one_line:
                    origin_router = re.sub('^  OriginRouter: ', '', one_line)

            if 'name=/' in one_line:
                one_line = re.sub('^      name=/', '/', one_line)
                lsdb = nfd_agent_pb2.LSDB(origin_router=origin_router,
                                          prefix=one_line)
                lsdbs.append(lsdb)

        return nfd_agent_pb2.NLSRLsdbListRes(lsdbs=lsdbs, ack=ack_reply)
Example #12
0
    def NLSRAdvertiseName(self, request, context):
        # nlsrc advertise or withdraw  <PREFIX> [option <save or delete>]
        cmd = "nlsrc"

        if request.mode:
            cmd += (" %s" % request.mode)
        if request.prefix:
            cmd += (" %s" % request.prefix)
        if request.save:
            cmd += (" %s" % request.save)

        ack_reply = nfd_agent_pb2.AckReply()
        if len(cmd) <= len('nlsrc advertise'):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = 'subcommand is not set'
            return ack_reply

        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        output_all = ps.communicate()[0]
        if is_error(output_all):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = ('%s' % output_all)
        else:
            ack_reply.ack_code = 'ok'
            ack_reply.ack_msg = ('%s' % output_all)
        return ack_reply
Example #13
0
    def NFDHostNotify(self, request, context):
        print("Agent Host Name  : %s" % request.name)
        print("Agent IP Address : %s" % request.ipaddr)
        print("Agent NIC Name : %s" % request.ifname)

        if len(request.host_adapters) > 0:
            for item in request.host_adapters:
                print("ipaddr=%s/%s, nicname=%s" %
                      (item.nic_ipaddr, item.nic_prefix, item.nic_name))
        else:
            print("Use only one network!!!")

        return nfd_agent_pb2.AckReply(ack_code='%s' % 'ok')
Example #14
0
    def NFDFaceCreate(self, request, context):
        # nfdc face create remote udp://router.example.net
        # nfdc face create remote ether://[08:00:27:01:01:01] local dev://eth2 persistency permanent
        # nfdc face create remote udp://router.example.net reliability on
        # nfdc face create remote udp://router.example.net congestion-marking-interval 100 default-congestion-threshold 65536
        # nfdc face create remote udp://router.example.net congestion-marking off
        # nfdc face create remote udp://router.example.net mtu 4000
        cmd = "nfdc face create"
        if request.remote:
            cmd += (" remote %s" % request.remote)
        if request.persistency:
            cmd += (" persistency %s" % request.persistency)
        if request.local:
            cmd += (" local %s" % request.local)
        if request.reliability:
            cmd += (" reliability %s" % request.reliability)
        if request.congestion_marking:
            cmd += (" congestion_marking %s" % request.congestion_marking)
        if request.congestion_marking_interval:
            cmd += (" congestion_marking_interval %s" %
                    request.congestion_marking_interval)
        if request.default_congestion_threshold:
            cmd += (" default_congestion_threshold %s" %
                    request.default_congestion_threshold)
        if request.mtu:
            cmd += (" mtu %s" % request.mtu)

        ack_reply = nfd_agent_pb2.AckReply()
        if len(cmd) <= len('nfdc face create'):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = 'subcommand is not set'
            return ack_reply

        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        output_all = ps.communicate()[0]
        if is_error(output_all):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = ('%s' % output_all)
        else:
            ack_reply.ack_code = 'ok'
            ack_reply.ack_msg = ('%s' % output_all)

        self.NLSRNeighborCreate(request)
        return ack_reply
Example #15
0
    def NFDFaceList(self, request, context):
        # Get Face List
        cmd = "nfdc face list"
        if request.faceid > 0:
            cmd += (" | grep 'faceid=%s '" % request.faceid)
        ps = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
        output_all = ps.communicate()[0]

        ack_reply = nfd_agent_pb2.AckReply()
        if is_error(output_all):
            ack_reply.ack_code = 'err'
            ack_reply.ack_msg = ('%s' % output_all)
            return nfd_agent_pb2.NFDFaceListRes(face=[], ack=ack_reply)
        else:
            ack_reply.ack_code = 'ok'

        output_all = output_all.replace(" re", "\tre")
        output_all = output_all.replace(" lo", "\tlo")
        output_all = output_all.replace(" co", "\tco")
        output_all = output_all.replace(" mt", "\tmt")
        output_all = output_all.replace(" ou", "\tou")
        output_all = output_all.replace(" fl", "\tfl")
        output_list = output_all.split("\n")

        faces = []
        for one_line in output_list:
            if one_line is None or one_line == '': continue
            item_list = one_line.split("\t")
            faceid, remote, local = ['', '', '']
            congestion, mtu, counters = ['', '', '']
            out, flags = ['', '']

            for item in item_list:
                if 'faceid=' in item:
                    faceid = item[len('faceid='):]
                elif 'remote=' in item:
                    remote = item[len('remote='):]
                elif 'local=' in item:
                    local = item[len('local='):]
                elif 'congestion=' in item:
                    congestion = item[len('congestion='):]
                elif 'mtu=' in item:
                    mtu = item[len('mtu='):]
                elif 'counters=' in item:
                    counters = item[len('counters='):]
                elif 'out=' in item:
                    out = item[len('out='):]
                elif 'flags=' in item:
                    flags = item[len('flags='):]

            face = nfd_agent_pb2.NFDFace(faceid=faceid,
                                         remote=remote,
                                         local=local,
                                         congestion=congestion,
                                         mtu=mtu,
                                         counters=counters,
                                         out=out,
                                         flags=flags)
            faces.append(face)

        return nfd_agent_pb2.NFDFaceListRes(faces=faces, ack=ack_reply)