Skip to content

Commit 1d6f0a2

Browse files
authored
Merge pull request #33 from logicog/mirror
Mirror
2 parents aa99921 + f93cfd4 commit 1d6f0a2

File tree

12 files changed

+245
-16
lines changed

12 files changed

+245
-16
lines changed

cmd_parser.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,37 @@ void parse_mirror(void)
273273
__xdata uint16_t rx_pmask = 0;
274274
__xdata uint16_t tx_pmask = 0;
275275

276+
if (cmd_words_b[1] > 0 && cmd_compare(1, "status")) {
277+
reg_read_m(RTL837x_MIRROR_CTRL);
278+
uint8_t mPort = sfr_data[3];
279+
if (mPort & 1) {
280+
print_string("Enabled: ");
281+
} else {
282+
print_string("NOT Enabled: ");
283+
}
284+
print_string("Mirroring port: ");
285+
if (!isRTL8373)
286+
write_char('0' + log_to_phys_port[mPort >> 1]);
287+
else
288+
write_char('0' + (mPort >> 1) + 1);
289+
reg_read_m(RTL837x_MIRROR_CONF);
290+
uint16_t m = sfr_data[0];
291+
m = (m << 8) | sfr_data[1];
292+
print_string(", Port mask RX: ");
293+
print_short(m);
294+
m = sfr_data[2];
295+
m = (m << 8) | sfr_data[3];
296+
print_string(", Port mask TX: ");
297+
print_short(m);
298+
write_char('\n');
299+
return;
300+
} else if (cmd_words_b[1] > 0 && cmd_compare(1, "off")) {
301+
port_mirror_del();
302+
return;
303+
}
304+
276305
if (!isnumber(cmd_buffer[cmd_words_b[1]])) {
277-
print_string("Port missing: port <mirroring port> [port][t/r]...");
306+
print_string("Port missing: mirror <mirroring port> [port][t/r]...");
278307
return;
279308
}
280309

html/eee.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<script src="/ports.js"></script>
44
<script src="/main.js"></script>
55
<link rel="stylesheet" href="style.css">
6-
<title>FreeSwitchOS Port Statistics</title>
6+
<title>EEE Configuration</title>
77
</head>
88
<body>
99
<nav id="sidebar"></nav>
@@ -15,8 +15,8 @@ <h1>EEE Status</h1>
1515
<tr> <th>Port</th> <th>2.5G</th> <th>1G</th> <th>100M</th> <th>2.5G</th> <th>1G</th> <th>100M</th> <th>Active?</th></tr>
1616
</table>
1717
<div>
18-
<input style="width:20%;padding: 8px 16px;margin-top: 2em;margin-right: 3em;" id="eee_enable" onclick="eeeSub(0, 1);" type="button" value="Enable EEE">
19-
<input style="width:20%;padding: 8px 16px;margin-top: 2em;" id="eee_enable" onclick="eeeSub(0, 0);" type="button" value="Disable EEE">
18+
<input style="width:20%;" class="action" id="eee_enable" onclick="eeeSub(0, 1);" type="button" value="Enable EEE">
19+
<input style="width:20%;" class="action" id="eee_enable" onclick="eeeSub(0, 0);" type="button" value="Disable EEE">
2020
</div>
2121
<script src="/eee.js"></script>
2222
<script src="/eee_sub.js"></script>

html/mirror.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<script src="/ports.js"></script>
4+
<script src="/main.js"></script>
5+
<link rel="stylesheet" href="style.css">
6+
<title>Mirror Configuration</title>
7+
</head>
8+
<body>
9+
<nav id="sidebar"></nav>
10+
<div style="margin-left:16%;padding:1px 16px;height:1000px;">
11+
<div id="ports"></div>
12+
<h1>Mirror Configuration</h1>
13+
<label class="tswitch">Enabled: <input id="me" type="checkbox"><span class="slider"></span></label><br/>
14+
<label for="mp">Mirroring Port:</label> <input type="number" id="mp" name="mp" min="1" max="9"/>
15+
<h2>Mirrored Ports (TX)</h2>
16+
<div id="mPortsTX"></div>
17+
<br />
18+
<h2>Mirrored Ports (RX)</h2>
19+
<div id="mPortsRX"></div>
20+
<br/> <input style="width:15%;" class="action" id="mirror_sub" onclick="mirrorSub();" type="button" value="Update / Create">
21+
<input style="width:15%;" class="action" id="mirror_del" onclick="mirrorDel();" type="button" value="Disable Mirroring">
22+
<script src="/mirror.js"></script>
23+
<script src="/mirror_sub.js"></script>
24+
</div>
25+
<script src="/navigation.js"></script>
26+
</body>
27+
</html>

html/mirror.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
var mirrorInterval = Number();
2+
const mirrors = ["mPortsTX", "mPortsRX"];
3+
4+
function mirrorForm() {
5+
if (!numPorts)
6+
return;
7+
clearInterval(mirrorInterval);
8+
for (let j=0; j < mirrors.length; j++) {
9+
console.log("Adding Mirror " + j)
10+
var m = document.getElementById(mirrors[j]);
11+
for (let i = 1; i <= numPorts; i++) {
12+
const d = document.createElement("div");
13+
d.classList.add("cbgroup");
14+
const l = document.createElement("label");
15+
l.innerHTML = "" + i;
16+
l.classList.add("cbgroup");
17+
const inp = document.createElement("input");
18+
inp.type = "checkbox"; inp.setAttribute("class","psel");
19+
inp.id = mirrors[j] + i;
20+
const o = document.createElement("img");
21+
if (pIsSFP[i - 1]) {
22+
o.src = "sfp.svg"; o.width ="60"; o.height ="60";
23+
} else {
24+
o.src = "port.svg"; o.width = "40"; o.height = "40";
25+
}
26+
l.appendChild(inp); l.appendChild(o);
27+
d.appendChild(l)
28+
m.appendChild(d);
29+
}
30+
}
31+
fetchMirror();
32+
}
33+
34+
function setM(p, c){
35+
document.getElementById(p).checked=c;
36+
}
37+
window.addEventListener("load", function() {
38+
mirrorInterval = setInterval(mirrorForm, 200);
39+
});
40+
41+
function fetchMirror() {
42+
var xhttp = new XMLHttpRequest();
43+
xhttp.onreadystatechange = function() {
44+
if (this.readyState == 4 && this.status == 200) {
45+
const s = JSON.parse(xhttp.responseText);
46+
console.log("MIRROR: ", JSON.stringify(s));
47+
document.getElementById('me').checked = s.enabled;
48+
document.getElementById('mp').value = s.mPort;
49+
let m_tx = parseInt(s.mirror_tx, 2);
50+
let m_rx = parseInt(s.mirror_rx, 2);
51+
for (let i = 1; i <= numPorts; i++) {
52+
setM("mPortsTX"+i, m_tx&1); setM("mPortsRX"+i, m_rx&1);
53+
m_tx = m_tx >> 1; m_rx = m_tx >> 1;
54+
}
55+
}
56+
};
57+
xhttp.open("GET", `/mirror.json`, true);
58+
xhttp.send();
59+
}

html/mirror_sub.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
async function mirrorSub() {
2+
var cmd = "mirror ";
3+
var mp=document.getElementById('mp').value
4+
if (!mp) {
5+
alert("Set Mirroring Port first");
6+
return;
7+
}
8+
document.getElementById(mirrors[0]+mp).checked=false;document.getElementById(mirrors[1]+mp).checked=false;
9+
cmd = cmd + mp;
10+
for (let i = 1; i <= numPorts; i++) {
11+
if (document.getElementById(mirrors[0] + i).checked && document.getElementById(mirrors[1] + i).checked)
12+
cmd = cmd + ` ${i}`;
13+
else if (document.getElementById(mirrors[0] + i).checked)
14+
cmd = cmd + ` ${i}t`;
15+
else if (document.getElementById(mirrors[1] + i).checked)
16+
cmd = cmd + ` ${i}r`;
17+
}
18+
if (cmd.length < 10) {
19+
alert("Select Mirrored Ports");
20+
return;
21+
}
22+
try {
23+
const response = await fetch('/cmd', {
24+
method: 'POST',
25+
body: cmd
26+
});
27+
console.log('Completed!', response);
28+
} catch(err) {
29+
console.error(`Error: ${err}`);
30+
}
31+
}
32+
async function mirrorDel() {
33+
var cmd = "mirror off";
34+
try {
35+
const response = await fetch('/cmd', {
36+
method: 'POST',
37+
body: cmd
38+
});
39+
location.reload();
40+
} catch(err) {
41+
console.error(`Error: ${err}`);
42+
}
43+
}

html/style.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,19 @@ input[type=submit] { padding: 8px 16px;background-color:#aaf;color:#000; margin-
4242
input[type=submit]:hover { background-color: #226; color: white;}
4343
button {padding: 8px; background-color:#99f; color:#000;}
4444
button:hover { background-color: #226; color: white;}
45-
46-
[type=checkbox] {
45+
.psel {
4746
position: absolute;
4847
opacity: 0;
4948
width: 0;
5049
height: 0;
5150
margin-top: 1em;
5251
}
53-
[type=checkbox] + img {
52+
.psel + img {
5453
cursor: pointer;
5554
opacity: 0.4;
5655
padding: 8px;
5756
}
58-
[type=checkbox]:checked + img {
57+
.psel:checked + img {
5958
/* outline: 2px solid #f00;*/
6059
opacity: 1.0;
6160
}
@@ -74,3 +73,4 @@ object {
7473
.isSFP{ opacity: .4; background-color: #660;}
7574
.isNOK{ color: #900;}
7675
.isOK{ color: #090;}
76+
.action{padding: 8px 16px;margin-top: 2em;margin-right: 3em; background-color: #aaf;color: #000;}

html/vlan.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ <h2>Tagged Ports</h2>
2525
<h2>Untagged Ports</h2>
2626
<div id="uPorts"><button type="button" style="transform: translateY(-100%); margin: 0 50px 0 0" onclick="utClicked(false);">Select all</button> </div>
2727
<script src="/vlan.js"></script>
28-
<br/> <input style="width:40%;" id="vlan_sub" onclick="vlanSub();" type="button" value="Update / Create">
28+
<br/> <input style="width:40%;" class="action" id="vlan_sub" onclick="vlanSub();" type="button" value="Update / Create">
2929
<script src="/vlan_sub.js"></script>
3030
</form>
3131
</div>

html/vlan.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function vlanForm() {
1313
l.innerHTML = "" + i;
1414
l.classList.add("cbgroup");
1515
const inp = document.createElement("input");
16-
inp.type = "checkbox";
16+
inp.type = "checkbox"; inp.setAttribute("class","psel");
1717
inp.id = "tport" + i;
1818
inp.setAttribute('onclick', `setC("u", ${i}, false);`);
1919
const o = document.createElement("img");

httpd/httpd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ void httpd_appcall(void)
441441
send_counters(q[19]-'0');
442442
} else if (is_word(q, "/eee.json")) {
443443
send_eee();
444+
} else if (is_word(q, "/mirror.json")) {
445+
send_mirror();
444446
} else {
445447
send_not_found();
446448
}

httpd/page_impl.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,45 @@ void send_counters(char port)
217217
}
218218

219219

220-
void send_eee()
220+
void send_mirror(void)
221+
{
222+
print_string("send_eee called\n");
223+
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
224+
print_string("sending EEE status\n");
225+
226+
reg_read_m(RTL837x_MIRROR_CTRL);
227+
uint8_t mPort = sfr_data[3];
228+
if (mPort & 1) {
229+
slen += strtox(outbuf + slen, "{\"enabled\":1,\"mPort\":");
230+
} else {
231+
slen += strtox(outbuf + slen, "{\"enabled\":0,\"mPort\":");
232+
}
233+
if (!isRTL8373)
234+
itoa_html(log_to_phys_port[mPort >> 1]);
235+
else
236+
itoa_html((mPort >> 1) + 1);
237+
238+
reg_read_m(RTL837x_MIRROR_CONF);
239+
uint16_t m = sfr_data[0];
240+
m = (m << 8) | sfr_data[1];
241+
slen += strtox(outbuf + slen, ",\"mirror_rx\":\"");
242+
for (uint8_t i = 0; i < 16; i++) {
243+
bool_to_html(m & 0x8000);
244+
m <<= 1;
245+
}
246+
m = sfr_data[2];
247+
m = (m << 8) | sfr_data[3];
248+
slen += strtox(outbuf + slen, "\",\"mirror_tx\":\"");
249+
for (uint8_t i = 0; i < 16; i++) {
250+
bool_to_html(m & 0x8000);
251+
m <<= 1;
252+
}
253+
char_to_html('\"');
254+
char_to_html('}');
255+
}
256+
257+
258+
void send_eee(void)
221259
{
222260
print_string("send_eee called\nsending EEE status\n");
223261
slen = strtox(outbuf, HTTP_RESPONCE_JSON);

0 commit comments

Comments
 (0)