ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2....

26
© 2018 National Institute of Information and Communications Technology 2018 8 30 日(木) 12 ICN 研究会ワークショップ Cefore アプリ開発ツール cefpyco 2018/8/30(木) 12ICN研究会ワークショップ ハンズオン

Upload: others

Post on 19-Jun-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

2018年8月30日(木)

第12回 ICN研究会ワークショップ

Ceforeアプリ開発ツール

cefpyco

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

Page 2: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

目次

cefpycoの概要

cefpycoのインストール

cefpycoを用いた通信

cefnetdへの接続

Dataパケットの送信*1

Interestパケットの送信

パケットの受信

簡易Consumerアプリの作成

簡易Producerアプリの作成

サンプルアプリCefApp

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

2

*1:本スライドではCob(Content Object)をDataまたはDataパケットと呼称

Page 3: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology 2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

cefpycoの概要

cefpyco (CEFore PYthon COmpact package)

ceforeアプリ開発用のpythonパッケージ

C言語で開発するより記述が楽

• 例: Interest を送るコード1 #include <stdio.h>2 #include <stdlib.h>3 #include <unistd.h>4 #include <ctype.h>5 #include <cefore/cef_define.h>6 #include <cefore/cef_client.h>7 #include <cefore/cef_frame.h>8 #include <cefore/cef_log.h>910 int main(int argc, char *argv[]) {11 CefT_Client_Handle fhdl;12 CefT_Interest_TLVs params_i;13 int res;14 cef_log_init ("cefpyco");15 cef_frame_init();16 res = cef_client_init(port_num, conf_path);17 if (res < 0) return -1;18 fhdl = cef_client_connect();19 if (fhdl < 1) return -1;20 memset(&params_i, 0, sizeof(CefT_Interest_TLVs));

21 res = cef_frame_conversion_uri_to_name("ccn:/test", params_i.name);

22 if (res < 0) return -1; // Failed to convert URI to name.;

23 params_i.name_len = res;24 params_i.hoplimit = 32;25 params_i.opt.lifetime_f = 1;26 params_i.opt.lifetime = 4000ull; /* 4 seconds */27 params_i.opt.symbolic_f = CefC_T_OPT_REGULAR;28 params_i.chunk_num_f = 1;29 params_i.chunk_num = 0;30 cef_client_interest_input(fhdl, &params_i);31 if (fhdl > 0) cef_client_close(fhdl);32 return 0;33 }

C言語版 Python版

1 import cefpyco

2

3 with cefpyco.create_handle() as h:

4 h.send_interest("ccn:/test", 0)

33行→4行

3

Page 4: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

cefpycoのダウンロード

https://cefore.net/download > Utilities > cefpyco

マニュアル(README.html)付属*1

*1: 2018/8/30現在は日本語マニュアルのみ

ここをクリック

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

4Practice

Page 5: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

ビルドとインストール

ライブラリのインストール

cefpycoのビルド

$ sudo apt-get install cmake python-pip

$ sudo pip install setuptools click numpy

$ tar -xzf cefpyco-0.2.1.tar.gz

$ cd cefpyco-0.2.1/cefpyco

$ cmake .

$ sudo make install

$ cd ..

$ sudo python

>> import cefpyco

>> (Ctrl-D)

# 任意のディレクトリにアーカイブを解凍

# “.”のつけ忘れに注意

# pythonでインポートして起動確認

# エラーが起きなければ正常

# Ctrl-D を押して終了

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

5Practice

Page 6: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

トラブルシューティング

Macでpipがインストールできない

以下を実行

$ brew install pyenv

$ pyenv install 3.7.0

$ pyenv versions # インストールversionの確認

$ sudo easy_install pip

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

6

Page 7: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

(再掲)バッファチューニング

Linux OS

Mac OS

2018/8/29(水)

第12回 ICN研究会ワークショップハンズオン

7

$ sudo sysctl –w net.core.rmem_default=10000000

$ sudo sysctl –w net.core.wmem_default=10000000

$ sudo sysctl –w net.core.rmem_max=10000000

$ sudo sysctl –w net.core.wmem_max=10000000

$ sudo sysctl –w net.local.stream.sendspace=2000000

$ sudo sysctl –w net.local.stream.recvspace=2000000

Practice

Page 8: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

cefpycoを用いた通信

① cefnetdへの接続

create_handle()メソッド

② Dataパケットの送信

send_data(name chunk_num, payload)メソッド

③ Interestパケットの送信

send_interest(name, chunk_num)メソッド

④ パケットの受信

receive()メソッド

⑤ 簡易Consumerアプリの作成

⑥ 簡易Producerアプリの作成

register(name)メソッド

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

8

Page 9: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

①cefnetdへの接続

1. 以下の内容のpythonファイルtest1.pyを作成

2. cefnetdを起動して実行(エラーが無ければ正常)

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

9

import cefpyco

with cefpyco.create_handle() as handle:

pass # ブロック開始時にcefnetdへ接続、終了時に切断

test1.py

cefore:~/cefpyco-0.2.1$ sudo csmgrdstart # if neededcefore:~/cefpyco-0.2.1$ sudo cefnetdstartcefore:~/cefpyco-0.2.1$ sudo python test1.py2018-08-30 15:14:00.123 [cefpyco] INFO: [client] Config directory is /usr/local/cefore2018-08-30 15:14:00.123 [cefpyco] INFO: [client] Local Socket Name is /tmp/cef_9896.02018-08-30 15:14:00.123 [cefpyco] INFO: [client] Listen Port is 9896

Practice

Page 10: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology 2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

C言語等のセミコロンや括弧の代わりにインデントで文・ブロックを表現

with構文:煩雑な開始/終了/例外処理を省略できる文法

代表例:ファイルオープン・クローズ

補足:pythonの文法10

# a=1, b=1のときはbと表示# a=1, b≠1のときはaと表示# a≠1のときは何もしない

if a == 1:if b == 1:

print(“b“)else:

print(“a“)

i f a = = 1 :p r i n t ( “ c o r r e c t “ )

e l s e :p r i n t ( ” e r r o r ” )

p r i n t ( “ e r r o r “ )Tab文字

エラー例• 空白4文字と空白2文字• 空白4文字とタブ1文字

ブロックの範囲を一目で見分けられる

インデント幅が揃っていないとバグ扱いなので要注意

print(“Begin.“)try:

h = cefpyco.CefpycoHandle()h.begin()print(“Do something.“)

except Exception as e:print(e)# 例外処理

finally:h.end()

print(“End.“)

with構文無しの場合

print(“Begin.“)with cefpyco.create_handle() as h:

print(“Do something.“)print(“End.“)

with構文を用いた場合

Page 11: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

②Dataパケットの送信

1. 以下の内容のpythonファイルtest2.pyを作成

2. csmgrd・cefnetdを起動して実行

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

11

import cefpyco

with cefpyco.create_handle() as handle:# ccn:/testというコンテンツ名・チャンク番号0で# helloというテキストコンテンツをDataパケットとして送信handle.send_data("ccn:/test", 0, "hello")

test2.py

cefore:~/cefpyco-0.2.1$ sudo csmgrdstartcefore:~/cefpyco-0.2.1$ sudo cefnetdstartcefore:~/cefpyco-0.2.1$ sudo python test2.py…cefore:~/cefpyco-0.2.1$ csmgrstatus ccn:/…***** Cache Status Report *****Number of Cached Contents : 1[0]

Content Name : ccn:/test/Content Size : 5 Bytes Access Count : 0

csmgrdにDataが

アップロードされる

Practice

Page 12: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

③Interestパケットの送信

1. 以下の内容のpythonファイルtest3.pyを作成

2. (test2.py実行後に)test3.pyを実行

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

12

import cefpyco

with cefpyco.create_handle() as handle:# ccn:/testというコンテンツの0番目のチャンクを# 要求するInterestパケットを送信handle.send_interest("ccn:/test", 0)

test3.py

# (test2.pyのシナリオを実行)cefore:~/cefpyco-0.2.1$ sudo python test3.py…cefore:~/cefpyco-0.2.1$ csmgrstatus ccn:/…***** Cache Status Report *****Number of Cached Contents : 1[0]

Content Name : ccn:/test/Content Size : 5 Bytes Access Count : 1

Access Countが1だけ増加

Practice

Page 13: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

④パケットの受信

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

13

以下のコードでパケットを受信可能

receive()メソッド

実行後、約4秒の間 パケットを待ち受ける

• 成功するまで受信したい場合はwhileループ等が必要

CcnPacketInfoオブジェクトを返す

• 受信の成否やInterest/Dataに依らない

• プロパティ一覧は次ページで説明

import cefpyco

with cefpyco.create_handle() as handle:handle.send_interest(“ccn:/test”, 0) # Dataパケットを受信したい場合# handle.register(“ccn:/test”) # Interestパケットを受信したい場合info = handle.receive()

Page 14: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

CcnPacketInfoのプロパティ

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

14

プロパティ名 型 説明

is_succeeded, is_failed bool パケット受信の成否フラグ

is_interest, is_data bool受信したパケットがInterest/Dataか否かを表すフラグ(受信失敗時には両方ともFalseとなる)

name string URI形式(ccn:/~)の名前

name_len int URI形式の名前の長さ(name TLV長ではない)

chunk_num int チャンク番号

payload string (Dataパケットの場合)コンテンツのデータ

payload_len int (Dataパケットの場合)コンテンツのデータのバイト長

version int 受信パケットのバージョン値

type int 受信パケットのタイプ値

actual_data_len int 受信したパケットのヘッダを含むバイト長

Page 15: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

from time import sleepimport cefpyco

with cefpyco.create_handle() as handle:while True:

handle.send_interest("ccn:/test", 0)info = handle.receive()if info.is_succeeded and (info.name == "ccn:/test“) and (info.chunk_num == 0):

print("Success")print(info)break

sleep(1)

⑤簡易Consumerアプリの作成

以下の内容のpythonファイルconsumer.pyを作成

チャンクが1個しかないコンテンツccn:/testを受信

受信に成功するまでreceiveメソッドを繰り返す

穴埋め問題:

受信したCcnPacketInfoを見て受信に成功したか否か

を検証するif文を完成させよう

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

15Practice

consumer.py

Page 16: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

⑤簡易Consumerアプリの作成:解答

以下の内容のpythonファイルconsumer.pyを作成

チャンクが1個しかないコンテンツccn:/testを受信

受信に成功するまでreceiveメソッドを繰り返す

穴埋め問題:

受信したCcnPacketInfoを見て受信に成功したか否か

を検証するif文を完成させよう

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

16Practice

from time import sleepimport cefpyco

with cefpyco.create_handle() as handle:while True:

handle.send_interest("ccn:/test", 0)info = handle.receive()if info.is_succeeded and (info.name == "ccn:/test“) and (info.chunk_num == 0):

print("Success")print(info)break

sleep(1)

consumer.py

Page 17: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

consumer.pyの動作例

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

17Practice

cefore:~/cefpyco-0.2.1$ sudo csmgrdstart…cefore:~/cefpyco-0.2.1$ sudo cefnetdstart…cefore:~/cefpyco-0.2.1$ echo hello > test; cefputfile ccn:/test…cefore:~/cefpyco-0.2.1$ sudo python consumer.py [cefpyco] Configure directory is /usr/local/cefore2018-08-30 15:16:00.123 [cefpyco] INFO: [client] Config directory is /usr/local/cefore2018-08-30 15:16:00.123 [cefpyco] INFO: [client] Local Socket Name is /tmp/cef_9896.02018-08-30 15:16:00.123 [cefpyco] INFO: [client] Listen Port is 98962018-08-30 15:16:00.123 [cefpyco] INFO: Send interest (name: ccn:/test, #chunk: 0)SuccessInfo: Succeeded to receive Data packet with name 'ccn:/test' (#chunk: 0) and payload 'hello' (6 Bytes)

ccn:/testという名前のコンテンツの0番目のチャンクの

取得に成功

Page 18: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

import cefpyco

with cefpyco.create_handle() as handle:handle.register("ccn:/test")while True:

info = handle.receive()if info.is_succeeded and (info.name == "ccn:/test“) and (info.chunk_num == 0):

handle.send_data("ccn:/test", 0, "hello")# break # Uncomment if publisher provides content once

⑥簡易Producerアプリの作成

以下の内容のpythonファイルproducer.pyを作成

Interestを受信するにはregisterメソッドを用いる

• register(prefix): cefnetdがInterestを受信した際に、

Interestの名前とprefixが一致する場合はアプリに送るよ

うに登録するためのメソッド

穴埋め問題:

”ccn:/test”宛のInterestを受け取ったら”hello”とい

う文字列を返すifブロックを完成させよう

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

18Practice

producer.py

Page 19: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

⑥簡易Producerアプリの作成:解答

以下の内容のpythonファイルproducer.pyを作成

Interestを受信するにはregisterメソッドを用いる

• register(prefix): cefnetdがInterestを受信した際に、

Interestの名前とprefixが一致する場合はアプリに送るよ

うに登録するためのメソッド

穴埋め問題:

”ccn:/test”宛のInterestを受け取ったら”hello”とい

う文字列を返すifブロックを完成させよう

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

19Practice

import cefpyco

with cefpyco.create_handle() as handle:handle.register("ccn:/test")while True:

info = handle.receive()if info.is_succeeded and (info.name == "ccn:/test“) and (info.chunk_num == 0):

handle.send_data("ccn:/test", 0, "hello")# break # Uncomment if publisher provides content once

producer.py

Page 20: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

producer.pyの動作例

csmgrdを無効にしてから、2つの端末で以下を実行

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

20Practice

cefore:~/cefpyco-0.2.1$ sudo cefnetdstart…cefore:~/cefpyco-0.2.1$ sudo python producer.py[cefpyco] Configure directory is /usr/local/cefore2018-08-30 15:19:00.123 [cefpyco] INFO: [client] Config directory is /usr/local/cefore2018-08-30 15:19:00.123 [cefpyco] INFO: [client] Local Socket Name is /tmp/cef_9896.02018-08-30 15:19:00.123 [cefpyco] INFO: [client] Listen Port is 9896

端末1(producer)

cefore:~/cefpyco-0.2.1$ sudo python consumer.py[cefpyco] Configure directory is /usr/local/cefore2018-08-30 15:19:10.123 [cefpyco] INFO: [client] Config directory is /usr/local/cefore2018-08-30 15:19:10.123 [cefpyco] INFO: [client] Local Socket Name is /tmp/cef_9896.02018-08-30 15:19:10.123 [cefpyco] INFO: [client] Listen Port is 98962018-08-30 15:19:10.123 [cefpyco] INFO: Send interest (name: ccn:/test, #chunk: 0)SuccessInfo: Succeeded in receiving Data packet with name 'ccn:/test' (#chunk: 0) and payload 'hello' (5 Bytes)

端末2(consumer)

コンテンツ配布開始

csmgrd無しで取得に成功

Page 21: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

サンプルアプリ CefApp

cefpyco/cefappディレクトリ内の2つのアプリ

cefappconsumer.py: Consumerアプリ

cefappproducer.py: Producerアプリ

特徴

先ほどの簡易アプリと異なり、複数チャンクから成る

コンテンツの送受信に対応

入出力はインライン・標準入出力・ファイルの3種類

cefappconsumerはパイプライン処理を実装

詳細な使用法はREADME 5章参照

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

21

Page 22: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

CefApp動作例

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

22

cefore:~/cefpyco-0.2.1$ sudo cefnetdstart…cefore:~/cefpyco-0.2.1$ ./cefappproducer.py ccn:/test hello[cefpyco] Configure directory is /usr/local/ceforeYYYY-MM-DD hh:mm:ss.xxx [cefpyco] INFO: [client] Config directory is /usr/local/ceforeYYYY-MM-DD hh:mm:ss.xxx [cefpyco] INFO: [client] Local Socket Name is /tmp/cef_9896.0YYYY-MM-DD hh:mm:ss.xxx [cefpyco] INFO: [client] Listen Port is 9896[cefapp] Receiving Interest...

端末1(producer)

cefore:~/cefpyco-0.2.1$ sudo ./cefappconsumer.py ccn:/test[cefpyco] Configure directory is /usr/local/ceforeYYYY-MM-DD hh:mm:ss.xxx [cefpyco] INFO: [client] Config directory is /usr/local/ceforeYYYY-MM-DD hh:mm:ss.xxx [cefpyco] INFO: [client] Local Socket Name is /tmp/cef_9896.0YYYY-MM-DD hh:mm:ss.xxx [cefpyco] INFO: [client] Listen Port is 9896YYYY-MM-DD hh:mm:ss.xxx [cefpyco] INFO: Send interest (name: ccn:/test/meta, #chunk: 0)YYYY-MM-DD hh:mm:ss.xxx [cefpyco] INFO: Send interest (name: ccn:/test, #chunk: 0)[cefapp] Succeed to receive.hello

端末2(consumer)

コンテンツ配布開始

コンテンツ取得に成功

Page 23: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

発展課題

複数チャンクの送受信を試してみよう

send_interestやsend_dataをチャンク数に応じて複数回実行するしてみよう

チャンク数を事前に知らなくても良い方法を考えよう

• 例:Dataが返ってこなくなるまでInterestを送る、チャンク数通知用のコンテンツを作る、etc.

cefgetfile/cefputfileと同等の機能を作ってみよう

ファイルを読み書きして送受信できるようにしよう

大きなファイルに対応するためのパイプライン処理を作ってみよう

• CefAppのコード等を参考

cefpyco/c_src/cefpyco.cやceforeのツールを参考に、C言語でアプリを作ってみよう

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

23Practice

Advanced

Page 24: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

主要なアプリ開発用API(C言語)

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

24Advanced

関数名 引数 説明cef_frame_init() 無し cef_frame_xxx()を使用する場合、最初に1度だけ実行。

cef_frame_conversion_uri_to_name• const char* name: URIを表す文字列• unsigned char* dst: TLVバイト列の書込先

URI形式の文字列(ccn:/~)をTLV(Type-Length-Value)バイト列形式に変更する。TLVのバイト長を返す(int)。

cef_frame_conversion_name_to_uri

• unsigned char* tlv: TLVを表すバイト列• unsigned int tlv_len: TLV長• char * dst: URIの書込先

TLV形式のバイト列をURI形式に変更する。URIのバイト長を返す(int)。

cef_client_connect 無しUNIXドメインソケットとしてアプリとcefnetd間の接続を確立し、そのコネクションを管理するためのハンドルを返す(CefT_Client_Handle)。

cef_client_close• CefT_Client_Handle fhdl: cef_client_connetctで生成したcefnetdとのハンドル

cefnetdとの接続を終了する。

cef_client_interest_input• CefT_Client_Handle fhdl: 同上• CefT_Interest_TLVs: Interest作成用パラメータ

パラメータで指定されたInterestパケットを生成し、cefnetdに送る。

cef_client_object_input• CefT_Client_Handle fhdl: 同上• CefT_Object_TLVs: Data作成用パラメータ

パラメータで指定されたDataパケットを生成し、cefnetdに送る。

cef_client_read

• CefT_Client_Handle fhdl: 同上• unsinged char* dst: 受信データの書込先• int dst_len: 書込先のバイト長

cefnetdからパケットを受信し、dstに書き込む。複数のメッセージが連結されている可能性がある。受信した全メッセージのバイト長を返す(int)。

cef_client_payload_get_with_info

• unsigned char * buf: cef_client_readで受信したバイト列

• int buf_len: バイト長• struct cef_app_frame* dst: 受信データ書込先

cefnetdから受け取ったメッセージから1パケット分のDataパケットを読み込み、struct cef_app_frameに格納する(Interestパケットは非対応)。読み残したメッセージ長を返す(int)。

cef_client_name_reg

• CefT_Client_Handle fhdl: 同上• uint16_t command: 命令• const unsigned char * name: name TLV• uint16_t name_len: name TLV長

cefnetdからInterestを受信するために、cefnetdに名前を登録(もしくは登録解除)する。commandにCefC_App_Regを指定すると登録、CefC_App_DeRegを指定すると登録解除する。

cef_client_prefix_reg 同上cef_client_name_regはnameが完全一致するInterestのみ受け取るが、これはプレフィックスマッチするInterest

を受け取れる。

※ cefore 0.7.2a時点ではInterestのパース関数は無い(cefpyco/c_src/cefparse/cpcparse_interest.c等を参考)

※要include: cefore/cef_frame.h, cefore/cef_client.h, cefore/cef_define.h

Page 25: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology

主要なアプリ開発用構造体(C言語)

型 変数名 説明

uint8_t hoplimit 固定ヘッダに設定される最大ホップ数。

unsigned char name[x] Name TLV。

uint16_t name_len Name長(単位:バイト)。

uint8_t chunk_num_f チャンク番号をName TLVに含める場合は非0

を設定。

uint32_t chunk_num Name TLVに含めるチャンク番号。

uint8_t nonce_f NonceをName TLVに含める場合は非0を設定。

uint64_t nonce Name TLVに含めるNonce値(0可)。Nameが一致してもNonce値が異なる場合、PITエントリ作成時に集約されなくなる。

CefT_Option_TLVs opt Hop-by-hop Optionヘッダに追加するパラメータ。

2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

25Advanced

型 変数名 説明 対象パケット

uint8_t lifetime_f Lifetimeを設定する場合は非0を設定 Interest

uint16_t lifetime Lifetimeをミリ秒で設定(0可) Interest

uint8_t cachetime_f Recommended Cache Time (RCT)を設定する場合は非0を設定

Content Object

uint64_t cachetime Recommended Cache Time (RCT)をミリ秒で設定(0可)

Content Object

uint16_t symbolic_f Symbolic識別子

Regular Interest: 0x0000

Long Life Interest: 0x0001

Interest

型 変数名 説明

unsigned char name[x] Name TLV。

uint16_t name_len Name長(単位:バイト)。

uint8_t chunk_num_f チャンク番号をName TLVに含める場合は非0

を設定。

uint32_t chunk_num Name TLVに含めるチャンク番号。

unsigned char meta[x] Meta Data。

uint16_t meta_len Meta Data長(単位:バイト)。

CefT_Option_TLVs opt Hop-by-hop Optionヘッダに追加するパラメータ。

unsigned char payload[x] ペイロードとなるバイト列。

uint16_t payload_len ペイロード長(単位:バイト)。

uint64_t expiry Content Objectの有効期限(UNIX Time、単位:ミリ秒)。

型 変数名 説明

uint32_t version CefC_App_Version(0xCEF00101)

uint32_t type CefC_App_Type_Internal(0x10000000)

uint64_t actual_data_len 実有効データ長(version~payload_lenまでの長さ+name_len+

payload_len+CefC_App_Magic_Noサイズ(4byte))。

unsigned char* name data_entityに格納したname部の先頭アドレス。

uint16_t name_len name長。

uint32_t chunk_num チャンク番号。

unsigned char* payload data_entityに格納したpayload部の先頭アドレス。

uint16_t payload_len payload長。

unsigned char data_entity[Cef

C_Max_Length]

name、payloadの実体を前詰めで格納し、最後にトレイラ(CefC_App_Magic_No)を設定する。最大65535バイト。

CefT_ Interest_TLVs

CefT_Object_TLVs

CefT_Option_TLVs

st ruct cef_app_frame

Page 26: Ceforeアプリ開発ツールicn/wp-content/uploads/2018/08/...2. (test2.py実行後に)test3.pyを実行 2018/8/30(木) 第12回ICN研究会ワークショップハンズオン

© 2018 National Institute of Information and Communications Technology 2018/8/30(木)

第12回 ICN研究会ワークショップハンズオン

26