예제 #1
0
 def make_subdata_cmd(self,
                      prefix,
                      dataname,
                      seq,
                      lifetime=None,
                      subinfo: SubInfo = None) -> (str, Any):
     """
     make subdata command
     :param prefix: datarn_prefix
     :type prefix: str
     :param dataname: dataname
     :type dataname: str
     :param seq: sequence no.
     :type seq: int
     :param subinfo: subinfo
     :type subinfo: SubInfo
     :return: command, interest_param, app_param
     """
     # make a subdatareq command name with args
     #command = Name.to_str(prefix + "/" + CMD_SUBDATAREQ + dataname + f'/{seq:d}')
     command = prefix + "/" + PSKCmd.commands[
         "CMD_SD"] + dataname + "/" + str(seq)
     # set interest parameter
     i_param = InterestParam()
     i_param.must_be_fresh = True
     i_param.nonce = gen_nonce()
     i_param.lifetime = (lifetime if lifetime else INT_LT_10)
     # make a app_params for subscription
     param = PSKParameters(subinfo=subinfo)
     str_app_param = json.dumps(param, default=serialize)
     return command, i_param, bytes(str_app_param, 'utf-8')
예제 #2
0
 def make_irdel_cmd(self,
                    prefix,
                    dataname,
                    rawpacket: BinaryStr = None) -> (str, Any):
     """
     make irdel command
     :param prefix: ir_prefix
     :type prefix: str
     :param dataname: dataname
     :type dataname: str
     :param rawpacket: raw interest packet
     :type bytes: 
     :return: command, interest_param, app_param
     """
     # make a irmod command name with args
     command = prefix + "/" + PSKCmd.commands["CMD_MD"] + dataname
     # set interest parameter
     i_param = InterestParam()
     i_param.must_be_fresh = True
     i_param.nonce = gen_nonce()
     i_param.lifetime = INT_LT_4
     # make app_param for Infomation Registry (raw interest packet)
     str_rawpacket = rawpacket.decode('utf-8')
     param = PSKParameters(rawpacket=str_rawpacket)
     str_app_param = json.dumps(param, default=serialize)
     return command, i_param, bytes(str_app_param, 'utf-8')
예제 #3
0
 def make_subtopic_cmd(self,
                       prefix,
                       dataname,
                       subinfo: SubInfo = None) -> (str, Any):
     """
     make subtopic command
     :param prefix: network_prefix or topicrn_prefix
     :type prefix: str
     :param dataname: topic name
     :type dataname: str
     :param subinfo: subscription information
     :type subinfo: SubInfo
     :return: command, interest_param, app_param
     """
     # make a subtopic command name with args
     command = prefix + "/" + PSKCmd.commands["CMD_ST"] + dataname
     # set interest parameter
     i_param = InterestParam()
     i_param.must_be_fresh = True
     i_param.nonce = gen_nonce()
     i_param.lifetime = INT_LT_10
     # make a app_params for subscription
     param = PSKParameters(subinfo=subinfo)
     str_app_param = json.dumps(param, default=serialize)
     return command, i_param, bytes(str_app_param, 'utf-8')
예제 #4
0
 def make_pubdata_cmd(self,
                      prefix,
                      dataname,
                      seq,
                      pubdatainfo: PubDataInfo = None) -> (str, Any):
     """
     make pubdata command
     :param prefix: network_prefix
     :type prefix: str
     :param dataname: dataname for publishing data
     :type dataname: str
     :param seq: sequence no.
     :type seq: int
     :param pubed_data: pubed data
     :type pubed_data: any
     :return: command, interest_param, app_param
     """
     # make a pubdata command name with args
     command = prefix + "/" + PSKCmd.commands[
         "CMD_PD"] + dataname + '/' + str(seq)
     # set interest parameter
     i_param = InterestParam()
     i_param.must_be_fresh = True
     i_param.nonce = gen_nonce()
     i_param.lifetime = INT_LT_4
     param = PSKParameters(pubdatainfo=pubdatainfo)
     str_app_param = json.dumps(param, default=serialize)
     return command, i_param, bytes(str_app_param, 'utf-8')
예제 #5
0
 def make_pubadv_cmd(self,
                     prefix: str,
                     dataname: str,
                     pubadvinfo: PubAdvInfo = None,
                     irinfo: IRInfo = None,
                     rninfo: RNInfo = None) -> (str, Any):
     """
     make pubadv command
     :param prefix: network_prefix or broker_prefix
     :type prefix: str
     :param dataname: dataname for publishing data
     :type dataname: str
     :param pubinfo: pubadvinfo
     :type pubinfo: PubAdvInfo
     :param irinfo: irinfo
     :type irinfo: IRInfo
     :param rninfo: rninfo
     :type rninfo: RNInfo
     :return: command, interest_param, app_param
     """
     # make a pubadv command name with args
     #command = Name.to_str(prefix + "/" + CMD_PUBADV + dataname)
     command = prefix + "/" + PSKCmd.commands["CMD_PA"] + dataname
     # set interest parameter
     i_param = InterestParam()
     i_param.must_be_fresh = True
     i_param.nonce = gen_nonce()
     i_param.lifetime = INT_LT_10
     param = PSKParameters(pubadvinfo=pubadvinfo,
                           irinfo=irinfo,
                           rninfo=rninfo)
     str_app_param = json.dumps(param, default=serialize)
     return command, i_param, bytes(str_app_param, 'utf-8')
예제 #6
0
 def make_generic_cmd(self,
                      command: str,
                      prefix: str,
                      dataname: str = "/_",
                      pubadvinfo: PubAdvInfo = None,
                      irinfo: IRInfo = None,
                      rninfo: RNInfo = None,
                      **kwargs) -> (str, Any):
     """
     make generic command
     :param prefix: network_prefix or broker_prefix
     :type prefix: str
     :param dataname: dataname for publishing data
     :type dataname: str
     :param pubinfo: pubadvinfo
     :type pubinfo: PubAdvInfo
     :param irinfo: irinfo
     :type irinfo: IRInfo
     :param rninfo: rninfo
     :type rninfo: RNInfo
     :return: command, interest_param, app_param
     """
     command = prefix + "/" + command + dataname
     # set interest parameter
     i_param = InterestParam()
     i_param.must_be_fresh = True
     i_param.nonce = gen_nonce()
     i_param.lifetime = INT_LT_10
     param = PSKParameters(pubadvinfo=pubadvinfo,
                           irinfo=irinfo,
                           rninfo=rninfo,
                           **kwargs)
     str_app_param = json.dumps(param, default=serialize)
     return command, i_param, bytes(str_app_param, 'utf-8')
예제 #7
0
 def test_interest_params():
     name = '/local/ndn/prefix'
     int_param = InterestParam()
     int_param.can_be_prefix = True
     int_param.must_be_fresh = True
     int_param.hop_limit = 1
     int_param.nonce = 0
     int_param.lifetime = 10
     interest = make_interest(name, int_param)
     assert (interest == b'\x05\x26\x07\x14\x08\x05local\x08\x03ndn\x08\x06prefix'
                         b'\x21\x00\x12\x00\x0a\x04\x00\x00\x00\x00\x0c\x01\x0a\x22\x01\x01')
예제 #8
0
 def make_pubunadv_cmd(self,
                       prefix,
                       dataname,
                       pubadvinfo: PubAdvInfo = None) -> (str, Any):
     """
     make pubunadv command
     :param prefix: network_prefix or broker_prefix
     :type prefix: str
     :param dataname: dataname for unpublishing data
     :type dataname: str
     :param pubadvinfo: pub information
     :type pubadvinfo: 
     :return: command, interest_param, app_param
     """
     # make a pubunadv command name with args
     command = prefix + "/" + PSKCmd.commands["CMD_PU"] + dataname
     # set interest parameter
     i_param = InterestParam()
     i_param.must_be_fresh = True
     i_param.nonce = gen_nonce()
     i_param.lifetime = INT_LT_10
     param = PSKParameters(pubadvinfo=pubadvinfo)
     str_app_param = json.dumps(param, default=serialize)
     return command, i_param, bytes(str_app_param, 'utf-8')