2 * Copyright (C) 2014 SDN Hub
4 * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.
5 * You may not use this file except in compliance with this License.
6 * You may obtain a copy of the License at
8 * http://www.gnu.org/licenses/gpl-3.0.txt
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16 var url = "http://" + location.hostname + ":8080";
21 function updateSwitchList() {
22 var switchSelect = document.getElementById("switch");
23 $.getJSON(url.concat("/v1.0/topology/switches"), function(switches){
24 $.each(switches, function(index, value){
25 var el = document.createElement("option");
26 el.textContent = value.dpid;
27 el.value = value.dpid;
28 switchSelect.appendChild(el);
30 portMap[value.dpid] = value.ports;
35 function updatePorts() {
36 var srcPortSelect = document.getElementById("src-ports");
37 removeAllChildren(srcPortSelect);
39 var allEl = document.createElement("option");
40 allEl.textContent = "all";
42 allEl.setAttribute('selected', 'selected');
43 srcPortSelect.appendChild(allEl);
45 var sinkPortSelect = document.getElementById("sink-ports");
46 removeAllChildren(sinkPortSelect);
48 var dpid = $('#switch').val();
49 $.each(portMap[dpid], function(key, value) {
50 var portNum = parseInt(value.port_no);
51 var el = document.createElement("option");
52 el.textContent = portNum;
54 srcPortSelect.appendChild(el);
56 el = document.createElement("option");
57 el.textContent = portNum;
59 sinkPortSelect.appendChild(el);
63 /* Format of the POST data is as follows:
65 {'fields': {' 'dl_src': mac string,
74 'sources': list of {'dpid': int, 'port_no': int},
75 'sinks': list of {'dpid': int, 'port_no': int}
80 function makePostData() {
82 var dpid = $('#switch').val();
83 var srcPorts = $('#src-ports').val();
84 var sinkPorts = $('#sink-ports').val();
86 if (sinkPorts == undefined) {
87 alert("Sink ports need to be specified.");
91 tapInfo['sources'] = [];
92 tapInfo['sinks'] = [];
93 tapInfo['fields'] = {};
95 if ($.inArray('all', srcPorts) != -1)
96 tapInfo.sources.push({'dpid': parseInt(dpid), 'port_no': 'all'});
98 $.each(srcPorts, function(index, value) {
99 port = {'dpid': parseInt(dpid), 'port_no': parseInt(value)};
100 tapInfo.sources.push(port);
103 $.each(sinkPorts, function(index, value) {
104 var port = {'dpid': parseInt(dpid), 'port_no': parseInt(value)};
105 tapInfo.sinks.push(port);
108 var macStr = $('#mac-addr').val();
109 var ipStr = $('#ip-addr').val();
110 var trafficType = $('#traffic-type').val();
111 var macClass = $('#mac-class').val();
112 var ipClass = $('#ip-class').val();
114 if (macClass != "--Ignore--") {
115 if (macStr == undefined || macStr=="") {
116 alert("MAC address needs to be specified.");
120 if (macClass == 'Source')
121 tapInfo.fields['dl_src'] = macStr;
122 else if (macClass == 'Destination')
123 tapInfo.fields['dl_dst'] = macStr;
124 else if (macClass == 'Src or Dest')
125 tapInfo.fields['dl_host'] = macStr;
127 if (ipClass != "--Ignore--") {
128 if (ipStr == undefined || ipStr=="") {
129 alert("MAC address needs to be specified.");
132 tapInfo.fields['dl_type'] = 0x800;
134 if (ipClass == 'Source')
135 tapInfo.fields['nw_src'] = ipStr;
136 else if (ipClass == 'Destination')
137 tapInfo.fields['nw_dst'] = ipStr;
138 else if (ipClass == 'Src or Dest')
139 tapInfo.fields['nw_host'] = ipStr;
141 if (trafficType == 'ARP') {
142 tapInfo.fields['dl_type'] = 0x806;
145 // Set prerequisite of IPv4 for all other types
146 else if (trafficType == 'ICMP') {
147 tapInfo.fields['dl_type'] = 0x800;
148 tapInfo.fields['nw_proto'] = 1;
150 } else if (trafficType == 'TCP') {
151 tapInfo.fields['dl_type'] = 0x800;
152 tapInfo.fields['nw_proto'] = 6;
154 else if (trafficType == 'HTTP') {
155 tapInfo.fields['dl_type'] = 0x800;
156 tapInfo.fields['nw_proto'] = 6;
157 tapInfo.fields['tp_port'] = 80;
159 else if (trafficType == 'HTTPS') {
160 tapInfo.fields['dl_type'] = 0x800;
161 tapInfo.fields['tp_port'] = 443;
162 tapInfo.fields['nw_proto'] = 6;
164 else if (trafficType == 'UDP') {
165 tapInfo.fields['dl_type'] = 0x800;
166 tapInfo.fields['nw_proto'] = 0x11;
168 else if (trafficType == 'DNS') {
169 tapInfo.fields['dl_type'] = 0x800;
170 tapInfo.fields['tp_port'] = 53;
171 tapInfo.fields['nw_proto'] = 0x11;
172 } else if (trafficType == 'DHCP') {
173 tapInfo.fields['dl_type'] = 0x800;
174 tapInfo.fields['tp_port'] = 67;
175 tapInfo.fields['nw_proto'] = 0x11;
177 console.log(tapInfo.fields);
182 function restoreMain() {
183 $("#main").replaceWith(originalMain);
184 $('#post-status').html('');
188 var tapInfo = makePostData();
189 if (tapInfo == undefined)
192 $.post(url.concat("/v1.0/tap/create"), JSON.stringify(tapInfo), function() {
195 originalMain = $('#main').clone();
196 $('#post-status').html('');
197 $('#main').html('<h2>Tap created</h2><p>Successfully created tap. Check the <a href="/web/stats.html#flow">flow statistics</a> to verify that the rules have been created.</p><button class="pure-button pure-button-primary" onclick="restoreMain()">Create another tap</button>');
200 $('#post-status').html('<p style="color:red; background:silver;">Error: Tap creation failed. Please verify your input.');
205 function clearTap() {
206 var tapInfo = makePostData();
207 if (tapInfo == undefined)
210 $.post(url.concat("/v1.0/tap/delete"), JSON.stringify(tapInfo), function() {
213 originalMain = $('#main').clone();
214 $('#post-status').html('');
215 $('#main').html('<h2>Tap deleted</h2><p>Successfully deleted tap. Check the <a href="/web/stats.html#flow">flow statistics</a> to verify that the rules have been deleted.</p><button class="pure-button pure-button-primary" onclick="restoreMain()">Create another tap</button>');
218 $('#post-status').html('<p style="color:red; background:silver;">Error: Tap deletion failed. Please verify your input.');