Example #1
0
def main():
    face = Face()
    current_nbr = 1
    max_nbr = 10
    PGI = 5

    f = open('measurements/app_measurments.txt','a')    
    f.seek(0)
    f.truncate()
    
    cow = 0
    v = 0
    counter = Counter(f, face)
    while current_nbr <= max_nbr:
        name = Name("farm1/cows")
        name.append("1")
        name.append("mvmnt")        
        name.appendSegment(v)
        interest = Interest(name)                
        counter._callbackCount = 0
        f.write('\n'+str(datetime.now().strftime('%X.%f')))
        face.expressInterest(interest, counter.onData, counter.onTimeout)
        
        while counter._callbackCount < 1 :
            face.processEvents()
            time.sleep(0.01)

        time.sleep(PGI)
        current_nbr+=1
        v+=1

    face.shutdown()
    f.close()
def generateData(baseName):
    '''
       This appends the segment number to the data name
    '''
    # just make up some data and return it
    ts = (time.time())
    segmentId = 0 # compatible with repo-ng test: may change to test segmented data

    versionComponent = baseName.get(-1) # should have a ts
    dataName = Name(baseName)
    dataName.appendSegment(segmentId)

    d = Data(dataName)
    content = "(" + str(ts) +  ") Data named " + dataName.toUri()
    d.setContent(content)
    d.getMetaInfo().setFinalBlockID(segmentId)
    d.getMetaInfo().setFreshnessPeriod(-1)
    if shouldSign:
        keychain.sign(d, certName)
    else:
        d.setSignature(fakeSignature)

    if shouldCollectStats:
        info = getInfoForVersion(versionComponent.toEscapedString())
        if info is not None:
            info['publish_time'] = ts

    return d
    def generateData(self, baseName):
        '''
           This appends the segment number to the data name, since repo-ng tends to expect it
        '''
        # just make up some data and return it
        ts = (time.time())
        segmentId = 0 # compatible with repo-ng test: may change to test segmented data

        versionStr = baseName.get(-1).toEscapedString()
        dataName = Name(baseName)
        dataName.appendSegment(segmentId)

        d = Data(dataName)
        content = "(" + str(ts) +  ") Data named " + dataName.toUri()
        d.setContent(content)
        d.getMetaInfo().setFinalBlockID(segmentId)
        d.getMetaInfo().setFreshnessPeriod(-1)
        if shouldSign:
            self.keychain.sign(d, self.certificateName)
        else:
            d.setSignature(self.fakeSignature)

        stats.insertDataForVersion(versionStr, {'publish_time':time.time()})
        logger.debug('Publishing: '+d.getName().toUri())
        return d
def onDataInterest(prefix, interest, transport, pxID):
    '''
       For publishing face
    '''
    # just make up some data and return it
    interestName = interest.getName()
    logger.info("Interest for " + interestName.toUri())

    ## CURRENTLY ASSUMES THERE'S A VERSION/SEGMENT SUFFIX!
    dataName = Name(interestName.getPrefix(-1))
    ts = (time.time())
    segmentId = 0
    try:
       segmentId = interestName().get(-1).toSegment()
    except:
        logger.debug("Could not find segment id!")
    dataName.appendSegment(segmentId)

    versionStr = interestName.get(-2).getValue().toRawStr()
    logger.debug('publishing ' + versionStr)
    info = getInfoForVersion(versionStr)

    d = Data(dataName)
    content = "(" + str(ts) +  ") Data named " + dataName.toUri()
    d.setContent(content)
    d.getMetaInfo().setFinalBlockID(segmentId)
    keychain.sign(d, certName)

    encodedData = d.wireEncode()
    now = time.time()

    if info is not None:
        info['publish_time'] = now
    transport.send(encodedData.toBuffer())
Example #5
0
 def request_segment(self, index):
     if index > self.highest_requested_segment:
         self.highest_requested_segment = index
     self.pending_segments.add(index)
     segment_name = Name(self.redirect.getName())
     segment_name.appendSegment(index)
     interest = Interest(segment_name)
     Log.info("Sent segment interest '{}'".format(
         Util.interest_to_string(interest)))
     self.node.face.expressInterest(interest, self.on_segment_data,
                                    self.on_segment_timeout)
Example #6
0
    def test_append(self):
        # could possibly split this into different tests
        uri = "/localhost/user/folders/files/%00%0F"
        name = Name(uri)
        name2 = Name("/localhost").append(Name("/user/folders/"))
        self.assertEqual(
            len(name2), 3, 'Name constructed by appending names has ' +
            str(len(name2)) + ' components instead of 3')
        self.assertTrue(name2[2].getValue() == Blob("folders"),
                        'Name constructed with append has wrong suffix')
        name2 = name2.append("files")
        self.assertEqual(
            len(name2), 4, 'Name constructed by appending string has ' +
            str(len(name2)) + ' components instead of 4')
        name2 = name2.appendSegment(15)
        self.assertTrue(
            name2[4].getValue() == Blob(bytearray([0x00, 0x0F])),
            'Name constructed by appending segment has wrong segment value')

        self.assertTrue(
            name2 == name,
            'Name constructed with append is not equal to URI constructed name'
        )
        self.assertEqual(name2.toUri(), name.toUri(),
                         'Name constructed with append has wrong URI')
Example #7
0
def main():
    seg = 0
    if len(sys.argv) < 3:
        print("argv error: please input capture or capture with #seg")
        exit(1)
    elif len(sys.argv) == 2:
        cmd = sys.argv[1]
    else:
        cmd = sys.argv[1]
        seg = sys.argv[2]

    loop = asyncio.get_event_loop()
    #face = ThreadsafeFace(loop, "localhost")
    face = Face("localhost")
    # Counter will stop the ioService after callbacks for all expressInterest.
    counter = Counter(loop, 3)

    seed = HMACKey(0,0,"seed","seedName")

    # Try to fetch anything.
    import time
    r = time.time()

    name1 = Name("/home/security/camera/0/"+cmd)
    name1.appendTimestamp(int(r))
    name1.appendSegment(int(seg))

    
    interest = Interest(name1)
    interest.setInterestLifetimeMilliseconds(3000)
    dump("Express name ", interest.toUri())
    face.expressInterest(interest, counter.onData, counter.onTimeout)
    
    """
    name2 = Name("/home/sensor/LED/T0829374723/turnOff")
    dump("Express name ", name2.toUri())
    face.expressInterest(name2, counter.onData, counter.onTimeout)
    """


    while counter._callbackCount < 1:
        face.processEvents()
        # We need to sleep for a few milliseconds so we don't use 100% of the CPU.
        time.sleep(2)

    face.shutdown()
Example #8
0
    def test_append(self):
        # could possibly split this into different tests
        uri = "/localhost/user/folders/files/%00%0F"
        name = Name(uri)
        name2 = Name("/localhost").append(Name("/user/folders/"))
        self.assertEqual(len(name2), 3, 'Name constructed by appending names has ' + str(len(name2)) + ' components instead of 3')
        self.assertTrue(name2[2].getValue() == Blob("folders"), 'Name constructed with append has wrong suffix')
        name2 = name2.append("files")
        self.assertEqual(len(name2), 4, 'Name constructed by appending string has ' + str(len(name2)) + ' components instead of 4')
        name2 = name2.appendSegment(15)
        self.assertTrue(name2[4].getValue() == Blob(bytearray([0x00, 0x0F])), 'Name constructed by appending segment has wrong segment value')

        self.assertTrue(name2 == name, 'Name constructed with append is not equal to URI constructed name')
        self.assertEqual(name2.toUri(), name.toUri(), 'Name constructed with append has wrong URI')
Example #9
0
File: names.py Project: MAHIS/PyNDN
		raise AssertionError("Got a different output: '%s' != '%s'" % (comp1, comp2))

n = Name(['hello', 'world'])

print(str(n))
if str(n) != "/hello/world":
	raise AssertionError("expected /hello/world")

n = Name("ndn:///testing/1/2/3/")
print(str(n))
if str(n) != "/testing/1/2/3":
	raise AssertionError("expected /testing/1/2/3 got: " + str(n))

if len(n) != 4:
	raise AssertionError("expected 4 components, got: " + len(n))

print(n.components)
assert(n.components == [b'testing', b'1', b'2', b'3'])

n = Name([1, '2', bytearray(b'3'), bytes(b'4')])
print(str(n))
assert(str(n) == "/1/2/3/4")

n = Name()
print(str(n))
n = n.appendSegment(5)
print(str(n))

assert(str(n) == "/%00%05")