{"action":"created","comment":{"url":"https://api.github.com/repos/pbhide/qemu-rocker/pulls/comments/28665142","id":28665142,"diff_hunk":"@@ -0,0 +1,216 @@\n+/*\n+ * QEMU rocker switch emulation - PCI device - P4 support\n+ *\n+ * Copyright (c) 2015 Parag Bhide <parag.bhide@barefootnetworks.com>\n+ *\n+ * This program is free software; you can redistribute it and/or modify\n+ * it under the terms of the GNU General Public License as published by\n+ * the Free Software Foundation; either version 2 of the License, or\n+ * (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ * GNU General Public License for more details.\n+ */\n+/*\n+ * Common functionality that can be leveraged by all P4 worlds\n+ */\n+#include <stdarg.h>\n+#include \"net/eth.h\"\n+#include \"qemu/iov.h\"\n+#include \"qemu/timer.h\"\n+#include \"qmp-commands.h\"\n+\n+#include \"rocker.h\"\n+#include \"rocker_hw.h\"\n+#include \"rocker_fp.h\"\n+#include \"rocker_tlv.h\"\n+#include \"rocker_world.h\"\n+#include \"rocker_desc.h\"\n+#include \"rocker_p4_rmt.h\"\n+#include \"rocker_p4_l2l3_features.h\"\n+#include \"rocker_p4_l2l3_enums.h\"\n+#include \"rocker_p4_l2l3_tables.h\"\n+#include \"rocker_p4_l2l3_tables_if.h\"\n+#include \"rocker_p4_l2l3.h\"\n+#include \"rocker_p4_common.h\"\n+\n+unsigned char *rocker_p4_iov_to_buffer(const struct iovec *iov, int iovcnt);\n+static int rocker_p4_rmt_table_cmd (struct p4_rmt_world *p4_rmt, \n+                                    struct desc_info *info,\n+                                    char *buf, unsigned short cmd,\n+                                    RockerTlv **tlvs);\n+\n+unsigned char *\n+rocker_p4_iov_to_buffer(const struct iovec *iov, int iovcnt)\n+{\n+    // convert iov to a single contiguous buffer for p4 model\n+    int len = 0;\n+    unsigned char *buf = NULL;\n+\n+    len = iov_size(iov, iovcnt);\n+    DPRINTF(\"convert %d iovs to a buffer of len %d\\n\", iovcnt, len);\n+    buf = malloc(len);\n+    if (buf == NULL) {\n+        DPRINTF(\"Cannot allocate buffer\\n\");\n+        return buf;\n+    }\n+    iov_to_buf(iov, iovcnt, 0, buf, len);\n+    return buf;\n+}\n+\n+\n+void rocker_p4_rmt_tx (int eg_port1, void *pkt, int len, int ig_port1, \n+                            void *cookie)\n+{\n+    struct iovec iov;\n+    int    iovcnt = 1;\n+    struct rocker *rocker;\n+    struct world *w;\n+    unsigned int fp_ig_port;\n+\n+    struct p4_rmt_world *p4_rmt = (struct p4_rmt_world *)cookie; // world_private(w);\n+    rocker = p4_rmt->rocker;\n+    w = p4_rmt->world;\n+\n+    fp_port_from_pport((unsigned int)ig_port1, &fp_ig_port);\n+\n+    DPRINTF(\"rocker_p4_rmt_tx to port %d, len %d.... \\n\", eg_port1, len);\n+    if (eg_port1 == 0) {\n+        DPRINTF(\"rocker_p4_rmt_tx DROP .... \\n\");\n+        free (pkt);\n+        return;\n+    }\n+    // convert the packet to iov\n+    iov.iov_len = len;\n+    iov.iov_base = pkt;\n+    if (rocker == NULL) {\n+        DPRINTF(\"\\\"rocker\\\" not found\\n\");\n+        return;\n+    }\n+    if (w == NULL) {\n+        DPRINTF(\"P4-RMT world not found\\n\");\n+        return;\n+    }\n+    // check for sup port\n+    if (p4_rmt->is_cpu_port(eg_port1)) {\n+        DPRINTF(\"rocker_p4_rmt_tx to CPU from ingress port %d, len %d.... \\n\", \n+                    ig_port1, len);\n+        rx_produce(w, ig_port1, &iov, iovcnt);\n+        return;\n+    }\n+    // call qemu_send to send out on switch port\n+    rocker_port_eg(rocker, eg_port1, &iov, iovcnt);\n+    return;\n+}\n+\n+static int rocker_p4_rmt_table_cmd (struct p4_rmt_world *p4_rmt, \n+                            struct desc_info *info,\n+                            char *buf, unsigned short cmd,\n+                            RockerTlv **tlvs)\n+{\n+    unsigned int    table_id;\n+    unsigned char   *entry;\n+    if (tlvs[ROCKER_TLV_P4_RMT_INFO_TABLE_ID] == NULL ||\n+        tlvs[ROCKER_TLV_P4_RMT_INFO_TABLE_ENTRY] == NULL) {\n+        DPRINTF(\"Missing TLVs\\n\");\n+        return 0;\n+    }\n+        \n+    table_id = rocker_tlv_get_u32(tlvs[ROCKER_TLV_P4_RMT_INFO_TABLE_ID]);\n+    entry = rocker_tlv_data(tlvs[ROCKER_TLV_P4_RMT_INFO_TABLE_ENTRY]);\n+\n+    DPRINTF(\"p4_rmt_table_cmd for table %d\\n\", table_id);\n+\n+    if (!p4_rmt->is_table_valid(table_id)) {\n+        DPRINTF(\"p4_rmt_table_cmd for invalide table %d\\n\", table_id);\n+        return 0;\n+    }\n+\n+    switch (cmd) {\n+        case ROCKER_TLV_CMD_TYPE_P4_RMT_TABLE_ENTRY_ADD:\n+            // check if fn is provided\n+            if (p4_rmt->table_ops[table_id].add) {\n+                p4_rmt->table_ops[table_id].add(entry);","path":"hw/net/rocker/rocker_p4_rmt.c","position":135,"original_position":135,"commit_id":"bf8a674f155d91f6e033ac55d99015854cff1ce4","original_commit_id":"bf8a674f155d91f6e033ac55d99015854cff1ce4","user":{"login":"scottfeldman","id":7387496,"avatar_url":"https://avatars.githubusercontent.com/u/7387496?v=3","gravatar_id":"","url":"https://api.github.com/users/scottfeldman","html_url":"https://github.com/scottfeldman","followers_url":"https://api.github.com/users/scottfeldman/followers","following_url":"https://api.github.com/users/scottfeldman/following{/other_user}","gists_url":"https://api.github.com/users/scottfeldman/gists{/gist_id}","starred_url":"https://api.github.com/users/scottfeldman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottfeldman/subscriptions","organizations_url":"https://api.github.com/users/scottfeldman/orgs","repos_url":"https://api.github.com/users/scottfeldman/repos","events_url":"https://api.github.com/users/scottfeldman/events{/privacy}","received_events_url":"https://api.github.com/users/scottfeldman/received_events","type":"User","site_admin":false},"body":"Hmm...it looks like entry is a binary blob.  How is it packed?  Are there un-aligned access issues?  How is it versioned?  How is big/little/host/network byte order handled?  It seems we want TLV-style encode/decode of the entry fields to answer all the questions.","created_at":"2015-04-20T05:48:41Z","updated_at":"2015-04-20T05:48:41Z","html_url":"https://github.com/pbhide/qemu-rocker/pull/1#discussion_r28665142","pull_request_url":"https://api.github.com/repos/pbhide/qemu-rocker/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/pbhide/qemu-rocker/pulls/comments/28665142"},"html":{"href":"https://github.com/pbhide/qemu-rocker/pull/1#discussion_r28665142"},"pull_request":{"href":"https://api.github.com/repos/pbhide/qemu-rocker/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/pbhide/qemu-rocker/pulls/1","id":33054705,"html_url":"https://github.com/pbhide/qemu-rocker/pull/1","diff_url":"https://github.com/pbhide/qemu-rocker/pull/1.diff","patch_url":"https://github.com/pbhide/qemu-rocker/pull/1.patch","issue_url":"https://api.github.com/repos/pbhide/qemu-rocker/issues/1","number":1,"state":"open","locked":false,"title":"P4 device","user":{"login":"pbhide","id":11168134,"avatar_url":"https://avatars.githubusercontent.com/u/11168134?v=3","gravatar_id":"","url":"https://api.github.com/users/pbhide","html_url":"https://github.com/pbhide","followers_url":"https://api.github.com/users/pbhide/followers","following_url":"https://api.github.com/users/pbhide/following{/other_user}","gists_url":"https://api.github.com/users/pbhide/gists{/gist_id}","starred_url":"https://api.github.com/users/pbhide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pbhide/subscriptions","organizations_url":"https://api.github.com/users/pbhide/orgs","repos_url":"https://api.github.com/users/pbhide/repos","events_url":"https://api.github.com/users/pbhide/events{/privacy}","received_events_url":"https://api.github.com/users/pbhide/received_events","type":"User","site_admin":false},"body":"Trying (playing with) pull requests","created_at":"2015-04-10T15:03:29Z","updated_at":"2015-04-20T05:48:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cdfcd0a60f81256500291da172e62f641bfb3a93","assignee":{"login":"pbhide","id":11168134,"avatar_url":"https://avatars.githubusercontent.com/u/11168134?v=3","gravatar_id":"","url":"https://api.github.com/users/pbhide","html_url":"https://github.com/pbhide","followers_url":"https://api.github.com/users/pbhide/followers","following_url":"https://api.github.com/users/pbhide/following{/other_user}","gists_url":"https://api.github.com/users/pbhide/gists{/gist_id}","starred_url":"https://api.github.com/users/pbhide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pbhide/subscriptions","organizations_url":"https://api.github.com/users/pbhide/orgs","repos_url":"https://api.github.com/users/pbhide/repos","events_url":"https://api.github.com/users/pbhide/events{/privacy}","received_events_url":"https://api.github.com/users/pbhide/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/pbhide/qemu-rocker/pulls/1/commits","review_comments_url":"https://api.github.com/repos/pbhide/qemu-rocker/pulls/1/comments","review_comment_url":"https://api.github.com/repos/pbhide/qemu-rocker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pbhide/qemu-rocker/issues/1/comments","statuses_url":"https://api.github.com/repos/pbhide/qemu-rocker/statuses/bf8a674f155d91f6e033ac55d99015854cff1ce4","head":{"label":"pbhide:p4_device","ref":"p4_device","sha":"bf8a674f155d91f6e033ac55d99015854cff1ce4","user":{"login":"pbhide","id":11168134,"avatar_url":"https://avatars.githubusercontent.com/u/11168134?v=3","gravatar_id":"","url":"https://api.github.com/users/pbhide","html_url":"https://github.com/pbhide","followers_url":"https://api.github.com/users/pbhide/followers","following_url":"https://api.github.com/users/pbhide/following{/other_user}","gists_url":"https://api.github.com/users/pbhide/gists{/gist_id}","starred_url":"https://api.github.com/users/pbhide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pbhide/subscriptions","organizations_url":"https://api.github.com/users/pbhide/orgs","repos_url":"https://api.github.com/users/pbhide/repos","events_url":"https://api.github.com/users/pbhide/events{/privacy}","received_events_url":"https://api.github.com/users/pbhide/received_events","type":"User","site_admin":false},"repo":{"id":33508712,"name":"qemu-rocker","full_name":"pbhide/qemu-rocker","owner":{"login":"pbhide","id":11168134,"avatar_url":"https://avatars.githubusercontent.com/u/11168134?v=3","gravatar_id":"","url":"https://api.github.com/users/pbhide","html_url":"https://github.com/pbhide","followers_url":"https://api.github.com/users/pbhide/followers","following_url":"https://api.github.com/users/pbhide/following{/other_user}","gists_url":"https://api.github.com/users/pbhide/gists{/gist_id}","starred_url":"https://api.github.com/users/pbhide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pbhide/subscriptions","organizations_url":"https://api.github.com/users/pbhide/orgs","repos_url":"https://api.github.com/users/pbhide/repos","events_url":"https://api.github.com/users/pbhide/events{/privacy}","received_events_url":"https://api.github.com/users/pbhide/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pbhide/qemu-rocker","description":"QEMU mirror for rocker switch development","fork":true,"url":"https://api.github.com/repos/pbhide/qemu-rocker","forks_url":"https://api.github.com/repos/pbhide/qemu-rocker/forks","keys_url":"https://api.github.com/repos/pbhide/qemu-rocker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pbhide/qemu-rocker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pbhide/qemu-rocker/teams","hooks_url":"https://api.github.com/repos/pbhide/qemu-rocker/hooks","issue_events_url":"https://api.github.com/repos/pbhide/qemu-rocker/issues/events{/number}","events_url":"https://api.github.com/repos/pbhide/qemu-rocker/events","assignees_url":"https://api.github.com/repos/pbhide/qemu-rocker/assignees{/user}","branches_url":"https://api.github.com/repos/pbhide/qemu-rocker/branches{/branch}","tags_url":"https://api.github.com/repos/pbhide/qemu-rocker/tags","blobs_url":"https://api.github.com/repos/pbhide/qemu-rocker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pbhide/qemu-rocker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pbhide/qemu-rocker/git/refs{/sha}","trees_url":"https://api.github.com/repos/pbhide/qemu-rocker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pbhide/qemu-rocker/statuses/{sha}","languages_url":"https://api.github.com/repos/pbhide/qemu-rocker/languages","stargazers_url":"https://api.github.com/repos/pbhide/qemu-rocker/stargazers","contributors_url":"https://api.github.com/repos/pbhide/qemu-rocker/contributors","subscribers_url":"https://api.github.com/repos/pbhide/qemu-rocker/subscribers","subscription_url":"https://api.github.com/repos/pbhide/qemu-rocker/subscription","commits_url":"https://api.github.com/repos/pbhide/qemu-rocker/commits{/sha}","git_commits_url":"https://api.github.com/repos/pbhide/qemu-rocker/git/commits{/sha}","comments_url":"https://api.github.com/repos/pbhide/qemu-rocker/comments{/number}","issue_comment_url":"https://api.github.com/repos/pbhide/qemu-rocker/issues/comments{/number}","contents_url":"https://api.github.com/repos/pbhide/qemu-rocker/contents/{+path}","compare_url":"https://api.github.com/repos/pbhide/qemu-rocker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pbhide/qemu-rocker/merges","archive_url":"https://api.github.com/repos/pbhide/qemu-rocker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pbhide/qemu-rocker/downloads","issues_url":"https://api.github.com/repos/pbhide/qemu-rocker/issues{/number}","pulls_url":"https://api.github.com/repos/pbhide/qemu-rocker/pulls{/number}","milestones_url":"https://api.github.com/repos/pbhide/qemu-rocker/milestones{/number}","notifications_url":"https://api.github.com/repos/pbhide/qemu-rocker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pbhide/qemu-rocker/labels{/name}","releases_url":"https://api.github.com/repos/pbhide/qemu-rocker/releases{/id}","created_at":"2015-04-06T22:15:55Z","updated_at":"2015-04-06T22:19:32Z","pushed_at":"2015-04-17T07:34:35Z","git_url":"git://github.com/pbhide/qemu-rocker.git","ssh_url":"git@github.com:pbhide/qemu-rocker.git","clone_url":"https://github.com/pbhide/qemu-rocker.git","svn_url":"https://github.com/pbhide/qemu-rocker","homepage":null,"size":77807,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"rocker"}},"base":{"label":"pbhide:master","ref":"master","sha":"d81b1fe70bd184ec19e8f793eaeba15a4ae936a0","user":{"login":"pbhide","id":11168134,"avatar_url":"https://avatars.githubusercontent.com/u/11168134?v=3","gravatar_id":"","url":"https://api.github.com/users/pbhide","html_url":"https://github.com/pbhide","followers_url":"https://api.github.com/users/pbhide/followers","following_url":"https://api.github.com/users/pbhide/following{/other_user}","gists_url":"https://api.github.com/users/pbhide/gists{/gist_id}","starred_url":"https://api.github.com/users/pbhide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pbhide/subscriptions","organizations_url":"https://api.github.com/users/pbhide/orgs","repos_url":"https://api.github.com/users/pbhide/repos","events_url":"https://api.github.com/users/pbhide/events{/privacy}","received_events_url":"https://api.github.com/users/pbhide/received_events","type":"User","site_admin":false},"repo":{"id":33508712,"name":"qemu-rocker","full_name":"pbhide/qemu-rocker","owner":{"login":"pbhide","id":11168134,"avatar_url":"https://avatars.githubusercontent.com/u/11168134?v=3","gravatar_id":"","url":"https://api.github.com/users/pbhide","html_url":"https://github.com/pbhide","followers_url":"https://api.github.com/users/pbhide/followers","following_url":"https://api.github.com/users/pbhide/following{/other_user}","gists_url":"https://api.github.com/users/pbhide/gists{/gist_id}","starred_url":"https://api.github.com/users/pbhide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pbhide/subscriptions","organizations_url":"https://api.github.com/users/pbhide/orgs","repos_url":"https://api.github.com/users/pbhide/repos","events_url":"https://api.github.com/users/pbhide/events{/privacy}","received_events_url":"https://api.github.com/users/pbhide/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pbhide/qemu-rocker","description":"QEMU mirror for rocker switch development","fork":true,"url":"https://api.github.com/repos/pbhide/qemu-rocker","forks_url":"https://api.github.com/repos/pbhide/qemu-rocker/forks","keys_url":"https://api.github.com/repos/pbhide/qemu-rocker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pbhide/qemu-rocker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pbhide/qemu-rocker/teams","hooks_url":"https://api.github.com/repos/pbhide/qemu-rocker/hooks","issue_events_url":"https://api.github.com/repos/pbhide/qemu-rocker/issues/events{/number}","events_url":"https://api.github.com/repos/pbhide/qemu-rocker/events","assignees_url":"https://api.github.com/repos/pbhide/qemu-rocker/assignees{/user}","branches_url":"https://api.github.com/repos/pbhide/qemu-rocker/branches{/branch}","tags_url":"https://api.github.com/repos/pbhide/qemu-rocker/tags","blobs_url":"https://api.github.com/repos/pbhide/qemu-rocker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pbhide/qemu-rocker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pbhide/qemu-rocker/git/refs{/sha}","trees_url":"https://api.github.com/repos/pbhide/qemu-rocker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pbhide/qemu-rocker/statuses/{sha}","languages_url":"https://api.github.com/repos/pbhide/qemu-rocker/languages","stargazers_url":"https://api.github.com/repos/pbhide/qemu-rocker/stargazers","contributors_url":"https://api.github.com/repos/pbhide/qemu-rocker/contributors","subscribers_url":"https://api.github.com/repos/pbhide/qemu-rocker/subscribers","subscription_url":"https://api.github.com/repos/pbhide/qemu-rocker/subscription","commits_url":"https://api.github.com/repos/pbhide/qemu-rocker/commits{/sha}","git_commits_url":"https://api.github.com/repos/pbhide/qemu-rocker/git/commits{/sha}","comments_url":"https://api.github.com/repos/pbhide/qemu-rocker/comments{/number}","issue_comment_url":"https://api.github.com/repos/pbhide/qemu-rocker/issues/comments{/number}","contents_url":"https://api.github.com/repos/pbhide/qemu-rocker/contents/{+path}","compare_url":"https://api.github.com/repos/pbhide/qemu-rocker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pbhide/qemu-rocker/merges","archive_url":"https://api.github.com/repos/pbhide/qemu-rocker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pbhide/qemu-rocker/downloads","issues_url":"https://api.github.com/repos/pbhide/qemu-rocker/issues{/number}","pulls_url":"https://api.github.com/repos/pbhide/qemu-rocker/pulls{/number}","milestones_url":"https://api.github.com/repos/pbhide/qemu-rocker/milestones{/number}","notifications_url":"https://api.github.com/repos/pbhide/qemu-rocker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pbhide/qemu-rocker/labels{/name}","releases_url":"https://api.github.com/repos/pbhide/qemu-rocker/releases{/id}","created_at":"2015-04-06T22:15:55Z","updated_at":"2015-04-06T22:19:32Z","pushed_at":"2015-04-17T07:34:35Z","git_url":"git://github.com/pbhide/qemu-rocker.git","ssh_url":"git@github.com:pbhide/qemu-rocker.git","clone_url":"https://github.com/pbhide/qemu-rocker.git","svn_url":"https://github.com/pbhide/qemu-rocker","homepage":null,"size":77807,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"rocker"}},"_links":{"self":{"href":"https://api.github.com/repos/pbhide/qemu-rocker/pulls/1"},"html":{"href":"https://github.com/pbhide/qemu-rocker/pull/1"},"issue":{"href":"https://api.github.com/repos/pbhide/qemu-rocker/issues/1"},"comments":{"href":"https://api.github.com/repos/pbhide/qemu-rocker/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/pbhide/qemu-rocker/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/pbhide/qemu-rocker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pbhide/qemu-rocker/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/pbhide/qemu-rocker/statuses/bf8a674f155d91f6e033ac55d99015854cff1ce4"}}}}