summaryrefslogtreecommitdiffstats
path: root/_tools/gpon-omci-vlan-parser.md
blob: 77c5b6b75de193c188592b0971113214ad8429f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
title: GPON OMCI VLAN Table parser
has_children: false
description: Tool for parse the GPON OMCI VLAN Table (ME 171)
layout: default
---

<h1>VLAN TABLE PARSER</h1>
<form id="vlan-table-parser" novalidate>
    <div class="form-floating mb-3">
        <input type="text" class="form-control" placeholder="VLAN TABLE in HEX" name="vlan-table-hex" id="vlan-table-hex" required>
        <label for="vlan-table-hex">VLAN TABLE in HEX</label>
        <div class="invalid-feedback">
            Please provide a valid input text.
        </div>
    </div>
    <div class="mb-3">
        <input type="submit" class="btn btn-primary" value="Decode!">
    </div>
    <div class="form-floating mb-3" id="to-place-table"></div>
</form>

<script type="text/javascript" src="/assets/js/omci-vlan.js"></script>
<script>          
    function fillVlanTable(table, vlanTableRule) {
        const tableNames = ["Filter outer priority",
                            "Filter outer VID",
                            "Filter outer TPID",
                            "Filter inner priority",
                            "Filter inner VID",
                            "Filter inner TPID",
                            "Filter ether type",
                            "Treatment tags to remove",
                            "Treatment outer priority",
                            "Treatment outer VID",
                            "Treatment outer TPID",
                            "Treatment inner priority",
                            "Treatment inner VID",
                            "Treatment inner TPID"];

    
        for (var j = 0; j < 14; j++) {
            var row = table.insertRow(j);
            var cell1 = row.insertCell(0);
            var cell2 = row.insertCell(1);
            
            cell1.innerHTML = tableNames[j];
            cell2.innerHTML = vlanTableRule[j];
        }
    }
    
    function makeVlanTables(formToPlaceTable, vlanTable) {
        for (const vlanRule of vlanTable) {
            var div = document.createElement('div');
            div.classList = "table-wrapper";
            var table = document.createElement('table');
            div.appendChild(table);
            fillVlanTable(table, vlanRule);
            formToPlaceTable.appendChild(div);
        }
    }
            
    var vlanTableForm = document.getElementById('vlan-table-parser');
    vlanTableForm.addEventListener('submit',(event) => {
        if (!vlanTableForm.checkValidity()) {
            event.preventDefault();
            [...vlanTableForm.elements].map(e => e.parentNode).forEach(e => e.classList.toggle('was-validated', true));
        } else {
            event.preventDefault();
            [...vlanTableForm.elements].map(e => e.parentNode).forEach(e => e.classList.toggle('was-validated', false));
            var fomrdata = new FormData(vlanTableForm);
            const hexString = fomrdata.get('vlan-table-hex');
            const vlanTable = vlanTableParse(hexString);
            const formToPlaceTable = document.getElementById('to-place-table');
            formToPlaceTable.innerHTML = '';
            makeVlanTables(formToPlaceTable, vlanTable);
        }
    });
</script>