{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/openshift-sdn/pulls/comments/45692347","id":45692347,"diff_hunk":"@@ -0,0 +1,161 @@\n+package ovs\n+\n+import (\n+\t\"encoding/hex\"\n+\t\"fmt\"\n+\t\"github.com/golang/glog\"\n+\t\"net\"\n+\t\"os/exec\"\n+\t\"strings\"\n+\t\"syscall\"\n+\n+\t\"github.com/openshift/openshift-sdn/pkg/netutils\"\n+\t\"github.com/openshift/openshift-sdn/plugins/osdn/api\"\n+)\n+\n+type FlowController struct {\n+\tmultitenant bool\n+}\n+\n+func NewFlowController(multitenant bool) *FlowController {\n+\treturn &FlowController{multitenant}\n+}\n+\n+func (c *FlowController) Setup(localSubnetCIDR, clusterNetworkCIDR, servicesNetworkCIDR string, mtu uint) error {\n+\t_, ipnet, err := net.ParseCIDR(localSubnetCIDR)\n+\tlocalSubnetMaskLength, _ := ipnet.Mask.Size()\n+\tlocalSubnetGateway := netutils.GenerateDefaultGateway(ipnet).String()\n+\tout, err := exec.Command(\"openshift-sdn-ovs-setup.sh\", localSubnetGateway, localSubnetCIDR, fmt.Sprint(localSubnetMaskLength), clusterNetworkCIDR, servicesNetworkCIDR, fmt.Sprint(mtu), fmt.Sprint(c.multitenant)).CombinedOutput()\n+\tif err != nil {\n+\t\tglog.Infof(\"Output of setup script:\\n%s\", out)\n+\t\texitErr, ok := err.(*exec.ExitError)\n+\t\tif ok {\n+\t\t\tstatus := exitErr.ProcessState.Sys().(syscall.WaitStatus)\n+\t\t\tif status.Exited() && status.ExitStatus() == 140 {\n+\t\t\t\t// valid, do nothing, its just a benevolent restart\n+\t\t\t\treturn nil\n+\t\t\t}\n+\t\t}\n+\t\tglog.Errorf(\"Error executing setup script: %v\\n\", err)\n+\t\treturn err\n+\t} else {\n+\t\tglog.V(5).Infof(\"Output of setup script:\\n%s\", out)\n+\t}\n+\treturn nil\n+}\n+\n+func (c *FlowController) GetName() string {\n+\tif c.multitenant {\n+\t\treturn MultiTenantPluginName()\n+\t} else {\n+\t\treturn SingleTenantPluginName()\n+\t}\n+}\n+\n+func (c *FlowController) AddOFRules(nodeIP, nodeSubnetCIDR, localIP string) error {\n+\tif nodeIP == localIP {\n+\t\treturn nil\n+\t}\n+\n+\tglog.V(5).Infof(\"AddOFRules for %s\", nodeIP)\n+\n+\tvar iprule, arprule string\n+\tcookie := generateCookie(nodeIP)\n+\tif c.multitenant {\n+\t\tiprule = fmt.Sprintf(\"table=7,cookie=0x%s,priority=100,ip,nw_dst=%s,actions=move:NXM_NX_REG0[]->NXM_NX_TUN_ID[0..31],set_field:%s->tun_dst,output:1\", cookie, nodeSubnetCIDR, nodeIP)\n+\t\tarprule = fmt.Sprintf(\"table=8,cookie=0x%s,priority=100,arp,nw_dst=%s,actions=move:NXM_NX_REG0[]->NXM_NX_TUN_ID[0..31],set_field:%s->tun_dst,output:1\", cookie, nodeSubnetCIDR, nodeIP)\n+\t} else {\n+\t\tiprule = fmt.Sprintf(\"table=0,cookie=0x%s,priority=100,ip,nw_dst=%s,actions=set_field:%s->tun_dst,output:1\", cookie, nodeSubnetCIDR, nodeIP)\n+\t\tarprule = fmt.Sprintf(\"table=0,cookie=0x%s,priority=100,arp,nw_dst=%s,actions=set_field:%s->tun_dst,output:1\", cookie, nodeSubnetCIDR, nodeIP)\n+\t}\n+\tout, err := exec.Command(\"ovs-ofctl\", \"-O\", \"OpenFlow13\", \"add-flow\", \"br0\", iprule).CombinedOutput()\n+\tif err != nil {\n+\t\tglog.Errorf(\"Error adding flow '%s': %s (%v)\", iprule, out, err)\n+\t\treturn err\n+\t}\n+\tout, err = exec.Command(\"ovs-ofctl\", \"-O\", \"OpenFlow13\", \"add-flow\", \"br0\", arprule).CombinedOutput()\n+\tif err != nil {\n+\t\tglog.Errorf(\"Error adding flow '%s': %s (%v)\", iprule, out, err)\n+\t\treturn err\n+\t}\n+\treturn nil\n+}\n+\n+func (c *FlowController) DelOFRules(nodeIP, localIP string) error {\n+\tif nodeIP == localIP {\n+\t\treturn nil\n+\t}\n+\n+\tglog.V(5).Infof(\"DelOFRules for %s\", nodeIP)\n+\n+\trule := fmt.Sprintf(\"cookie=0x%s/0xffffffff\", generateCookie(nodeIP))\n+\tout, err := exec.Command(\"ovs-ofctl\", \"-O\", \"OpenFlow13\", \"del-flows\", \"br0\", rule).CombinedOutput()\n+\tif err != nil {\n+\t\tglog.Errorf(\"Error deleting flow '%s': %s (%v)\", rule, out, err)","path":"plugins/osdn/ovs/controller.go","position":94,"original_position":94,"commit_id":"aec31973037f59bd772c4c3ca7ca373a2d314f76","original_commit_id":"aec31973037f59bd772c4c3ca7ca373a2d314f76","user":{"login":"pravisankar","id":1258630,"avatar_url":"https://avatars.githubusercontent.com/u/1258630?v=3","gravatar_id":"","url":"https://api.github.com/users/pravisankar","html_url":"https://github.com/pravisankar","followers_url":"https://api.github.com/users/pravisankar/followers","following_url":"https://api.github.com/users/pravisankar/following{/other_user}","gists_url":"https://api.github.com/users/pravisankar/gists{/gist_id}","starred_url":"https://api.github.com/users/pravisankar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pravisankar/subscriptions","organizations_url":"https://api.github.com/users/pravisankar/orgs","repos_url":"https://api.github.com/users/pravisankar/repos","events_url":"https://api.github.com/users/pravisankar/events{/privacy}","received_events_url":"https://api.github.com/users/pravisankar/received_events","type":"User","site_admin":false},"body":"nit: %q for quoted string('%s')","created_at":"2015-11-24T02:58:10Z","updated_at":"2015-11-24T02:58:10Z","html_url":"https://github.com/openshift/openshift-sdn/pull/208#discussion_r45692347","pull_request_url":"https://api.github.com/repos/openshift/openshift-sdn/pulls/208","_links":{"self":{"href":"https://api.github.com/repos/openshift/openshift-sdn/pulls/comments/45692347"},"html":{"href":"https://github.com/openshift/openshift-sdn/pull/208#discussion_r45692347"},"pull_request":{"href":"https://api.github.com/repos/openshift/openshift-sdn/pulls/208"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/openshift-sdn/pulls/208","id":50542562,"html_url":"https://github.com/openshift/openshift-sdn/pull/208","diff_url":"https://github.com/openshift/openshift-sdn/pull/208.diff","patch_url":"https://github.com/openshift/openshift-sdn/pull/208.patch","issue_url":"https://api.github.com/repos/openshift/openshift-sdn/issues/208","number":208,"state":"open","locked":false,"title":"Merge flatsdn and multitenant code","user":{"login":"danwinship","id":96040,"avatar_url":"https://avatars.githubusercontent.com/u/96040?v=3","gravatar_id":"","url":"https://api.github.com/users/danwinship","html_url":"https://github.com/danwinship","followers_url":"https://api.github.com/users/danwinship/followers","following_url":"https://api.github.com/users/danwinship/following{/other_user}","gists_url":"https://api.github.com/users/danwinship/gists{/gist_id}","starred_url":"https://api.github.com/users/danwinship/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danwinship/subscriptions","organizations_url":"https://api.github.com/users/danwinship/orgs","repos_url":"https://api.github.com/users/danwinship/repos","events_url":"https://api.github.com/users/danwinship/events{/privacy}","received_events_url":"https://api.github.com/users/danwinship/received_events","type":"User","site_admin":false},"body":"The flatsdn/\"kube\"/\"subnet\" and multitenant code have always been nearly identical so let's finally merge all the duplicate code (while still retaining the two plugin names with their different behavior).\r\n\r\n(Not yet tested... want to make sure that this makes sense first)\r\n\r\n@dcbw, @pravisankar","created_at":"2015-11-12T17:39:02Z","updated_at":"2015-11-24T02:58:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b17a943c8278d35646438ce246b8dd15b8a7dad5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openshift/openshift-sdn/pulls/208/commits","review_comments_url":"https://api.github.com/repos/openshift/openshift-sdn/pulls/208/comments","review_comment_url":"https://api.github.com/repos/openshift/openshift-sdn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openshift/openshift-sdn/issues/208/comments","statuses_url":"https://api.github.com/repos/openshift/openshift-sdn/statuses/aec31973037f59bd772c4c3ca7ca373a2d314f76","head":{"label":"danwinship:merge-plugins","ref":"merge-plugins","sha":"aec31973037f59bd772c4c3ca7ca373a2d314f76","user":{"login":"danwinship","id":96040,"avatar_url":"https://avatars.githubusercontent.com/u/96040?v=3","gravatar_id":"","url":"https://api.github.com/users/danwinship","html_url":"https://github.com/danwinship","followers_url":"https://api.github.com/users/danwinship/followers","following_url":"https://api.github.com/users/danwinship/following{/other_user}","gists_url":"https://api.github.com/users/danwinship/gists{/gist_id}","starred_url":"https://api.github.com/users/danwinship/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danwinship/subscriptions","organizations_url":"https://api.github.com/users/danwinship/orgs","repos_url":"https://api.github.com/users/danwinship/repos","events_url":"https://api.github.com/users/danwinship/events{/privacy}","received_events_url":"https://api.github.com/users/danwinship/received_events","type":"User","site_admin":false},"repo":{"id":33740026,"name":"openshift-sdn","full_name":"danwinship/openshift-sdn","owner":{"login":"danwinship","id":96040,"avatar_url":"https://avatars.githubusercontent.com/u/96040?v=3","gravatar_id":"","url":"https://api.github.com/users/danwinship","html_url":"https://github.com/danwinship","followers_url":"https://api.github.com/users/danwinship/followers","following_url":"https://api.github.com/users/danwinship/following{/other_user}","gists_url":"https://api.github.com/users/danwinship/gists{/gist_id}","starred_url":"https://api.github.com/users/danwinship/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danwinship/subscriptions","organizations_url":"https://api.github.com/users/danwinship/orgs","repos_url":"https://api.github.com/users/danwinship/repos","events_url":"https://api.github.com/users/danwinship/events{/privacy}","received_events_url":"https://api.github.com/users/danwinship/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/danwinship/openshift-sdn","description":"","fork":true,"url":"https://api.github.com/repos/danwinship/openshift-sdn","forks_url":"https://api.github.com/repos/danwinship/openshift-sdn/forks","keys_url":"https://api.github.com/repos/danwinship/openshift-sdn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/danwinship/openshift-sdn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/danwinship/openshift-sdn/teams","hooks_url":"https://api.github.com/repos/danwinship/openshift-sdn/hooks","issue_events_url":"https://api.github.com/repos/danwinship/openshift-sdn/issues/events{/number}","events_url":"https://api.github.com/repos/danwinship/openshift-sdn/events","assignees_url":"https://api.github.com/repos/danwinship/openshift-sdn/assignees{/user}","branches_url":"https://api.github.com/repos/danwinship/openshift-sdn/branches{/branch}","tags_url":"https://api.github.com/repos/danwinship/openshift-sdn/tags","blobs_url":"https://api.github.com/repos/danwinship/openshift-sdn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/danwinship/openshift-sdn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/danwinship/openshift-sdn/git/refs{/sha}","trees_url":"https://api.github.com/repos/danwinship/openshift-sdn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/danwinship/openshift-sdn/statuses/{sha}","languages_url":"https://api.github.com/repos/danwinship/openshift-sdn/languages","stargazers_url":"https://api.github.com/repos/danwinship/openshift-sdn/stargazers","contributors_url":"https://api.github.com/repos/danwinship/openshift-sdn/contributors","subscribers_url":"https://api.github.com/repos/danwinship/openshift-sdn/subscribers","subscription_url":"https://api.github.com/repos/danwinship/openshift-sdn/subscription","commits_url":"https://api.github.com/repos/danwinship/openshift-sdn/commits{/sha}","git_commits_url":"https://api.github.com/repos/danwinship/openshift-sdn/git/commits{/sha}","comments_url":"https://api.github.com/repos/danwinship/openshift-sdn/comments{/number}","issue_comment_url":"https://api.github.com/repos/danwinship/openshift-sdn/issues/comments{/number}","contents_url":"https://api.github.com/repos/danwinship/openshift-sdn/contents/{+path}","compare_url":"https://api.github.com/repos/danwinship/openshift-sdn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/danwinship/openshift-sdn/merges","archive_url":"https://api.github.com/repos/danwinship/openshift-sdn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/danwinship/openshift-sdn/downloads","issues_url":"https://api.github.com/repos/danwinship/openshift-sdn/issues{/number}","pulls_url":"https://api.github.com/repos/danwinship/openshift-sdn/pulls{/number}","milestones_url":"https://api.github.com/repos/danwinship/openshift-sdn/milestones{/number}","notifications_url":"https://api.github.com/repos/danwinship/openshift-sdn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/danwinship/openshift-sdn/labels{/name}","releases_url":"https://api.github.com/repos/danwinship/openshift-sdn/releases{/id}","created_at":"2015-04-10T16:58:50Z","updated_at":"2015-04-10T16:58:50Z","pushed_at":"2015-11-17T15:39:37Z","git_url":"git://github.com/danwinship/openshift-sdn.git","ssh_url":"git@github.com:danwinship/openshift-sdn.git","clone_url":"https://github.com/danwinship/openshift-sdn.git","svn_url":"https://github.com/danwinship/openshift-sdn","homepage":null,"size":538,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"openshift:master","ref":"master","sha":"ffa994725b5f60a0767698dc359d8a7783abb9a8","user":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"repo":{"id":29500061,"name":"openshift-sdn","full_name":"openshift/openshift-sdn","owner":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openshift/openshift-sdn","description":"","fork":false,"url":"https://api.github.com/repos/openshift/openshift-sdn","forks_url":"https://api.github.com/repos/openshift/openshift-sdn/forks","keys_url":"https://api.github.com/repos/openshift/openshift-sdn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openshift/openshift-sdn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openshift/openshift-sdn/teams","hooks_url":"https://api.github.com/repos/openshift/openshift-sdn/hooks","issue_events_url":"https://api.github.com/repos/openshift/openshift-sdn/issues/events{/number}","events_url":"https://api.github.com/repos/openshift/openshift-sdn/events","assignees_url":"https://api.github.com/repos/openshift/openshift-sdn/assignees{/user}","branches_url":"https://api.github.com/repos/openshift/openshift-sdn/branches{/branch}","tags_url":"https://api.github.com/repos/openshift/openshift-sdn/tags","blobs_url":"https://api.github.com/repos/openshift/openshift-sdn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openshift/openshift-sdn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openshift/openshift-sdn/git/refs{/sha}","trees_url":"https://api.github.com/repos/openshift/openshift-sdn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openshift/openshift-sdn/statuses/{sha}","languages_url":"https://api.github.com/repos/openshift/openshift-sdn/languages","stargazers_url":"https://api.github.com/repos/openshift/openshift-sdn/stargazers","contributors_url":"https://api.github.com/repos/openshift/openshift-sdn/contributors","subscribers_url":"https://api.github.com/repos/openshift/openshift-sdn/subscribers","subscription_url":"https://api.github.com/repos/openshift/openshift-sdn/subscription","commits_url":"https://api.github.com/repos/openshift/openshift-sdn/commits{/sha}","git_commits_url":"https://api.github.com/repos/openshift/openshift-sdn/git/commits{/sha}","comments_url":"https://api.github.com/repos/openshift/openshift-sdn/comments{/number}","issue_comment_url":"https://api.github.com/repos/openshift/openshift-sdn/issues/comments{/number}","contents_url":"https://api.github.com/repos/openshift/openshift-sdn/contents/{+path}","compare_url":"https://api.github.com/repos/openshift/openshift-sdn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openshift/openshift-sdn/merges","archive_url":"https://api.github.com/repos/openshift/openshift-sdn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openshift/openshift-sdn/downloads","issues_url":"https://api.github.com/repos/openshift/openshift-sdn/issues{/number}","pulls_url":"https://api.github.com/repos/openshift/openshift-sdn/pulls{/number}","milestones_url":"https://api.github.com/repos/openshift/openshift-sdn/milestones{/number}","notifications_url":"https://api.github.com/repos/openshift/openshift-sdn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openshift/openshift-sdn/labels{/name}","releases_url":"https://api.github.com/repos/openshift/openshift-sdn/releases{/id}","created_at":"2015-01-19T22:32:20Z","updated_at":"2015-11-19T16:53:27Z","pushed_at":"2015-11-21T00:17:23Z","git_url":"git://github.com/openshift/openshift-sdn.git","ssh_url":"git@github.com:openshift/openshift-sdn.git","clone_url":"https://github.com/openshift/openshift-sdn.git","svn_url":"https://github.com/openshift/openshift-sdn","homepage":null,"size":820,"stargazers_count":27,"watchers_count":27,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":29,"mirror_url":null,"open_issues_count":14,"forks":29,"open_issues":14,"watchers":27,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/openshift-sdn/pulls/208"},"html":{"href":"https://github.com/openshift/openshift-sdn/pull/208"},"issue":{"href":"https://api.github.com/repos/openshift/openshift-sdn/issues/208"},"comments":{"href":"https://api.github.com/repos/openshift/openshift-sdn/issues/208/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/openshift-sdn/pulls/208/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/openshift-sdn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openshift/openshift-sdn/pulls/208/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/openshift-sdn/statuses/aec31973037f59bd772c4c3ca7ca373a2d314f76"}}}}