aboutsummaryrefslogtreecommitdiffstats
path: root/uni/unibase/src/main/java/com/cablelabs/vcpe/uni/unibase/model/Uni.java
blob: 0edf3db4c4be3e1d23bb88ea36e594416a477f65 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*******************************************************************************
* Copyright (c) 2015 CableLabs Inc. and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution, and is available at
* http://www.apache.org/licenses/LICENSE-2.0
*******************************************************************************/

package com.cablelabs.vcpe.uni.unibase.model;

import com.cablelabs.vcpe.common.Dbg;

import javax.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by steve on 5/24/15.
 */

@XmlRootElement
public class Uni
{

    public enum SvcSpeed {
        UNASSIGNED   ("UNASSIGNED"),
        TEN_MEG      ("speed-10M"),
        HUNDRED_MEG  ("speed-100M"),
        ONE_GIG      ("speed-1G"),
        TEN_GIG      ("speed-10G");
                        private final String s;
                        private SvcSpeed(final String s) {this.s = s;}
                        @Override public String toString() { return s; }
    }

    public enum PhysMedium { // just a sampling of 802.3 phys layers
        UNASSIGNED     ("UNASSIGNED"),
        TEN_BASE_T     ("10BASE-T"),
        HUNDERED_BASE_T("100BASE-T"),
        GIG_BASE_T     ("1000BASE-T"),
        TEN_GIG_BASE_T ("10GBASE-T");
                            private final String s;
                            private PhysMedium(final String s) {this.s = s;}
                            @Override public String toString() { return s; }
        }

    public enum MacLayer {
        UNASSIGNED   ("UNASSIGNED"),
        IEEE_802_3   ("IEEE 802.3-2005");
                        private final String s;
                        private MacLayer(final String s) {this.s = s;}
                        @Override public String toString() { return s; }
        }

    public enum SyncMode {
        UNASSIGNED   ("UNASSIGNED"),
        ENABLED      ("syncEnabled"),
        DISABLED     ("syncDisabled");
                        private final String s;
                        private SyncMode(final String s) {this.s = s;}
                        @Override public String toString() { return s; }
        }

    public enum Type { // not sure what this is
        UNASSIGNED   ("UNASSIGNED"),
        UNITYPE      ("UNITYPE");
                        private final String s;
                        private Type(final String s) {this.s = s;}
                        @Override public String toString() { return s; }
        }


    private String id;
    private SvcSpeed speed;
    private String ipAddress;
    private String macAddress;
    private PhysMedium physicalMedium;
    private MacLayer macLayer;
    private SyncMode mode;
    private Type type;
    private long mtuSize;


    // no argument constructor required for JAX-RS
    public Uni() {
        this.id              = "unset";
        this.speed           = SvcSpeed.UNASSIGNED;
        this.ipAddress       = "unset";
        this.macAddress      = "unset";
        this.physicalMedium  = PhysMedium.UNASSIGNED;
        this.macLayer        = MacLayer.UNASSIGNED;
        this.mode            = SyncMode.UNASSIGNED;
        this.type            = Type.UNASSIGNED;
        this.mtuSize         = -1;
    }

    public void setAllProps (String id, SvcSpeed speed, String ipAddress,
                             String macAddress, PhysMedium physicalMedium,
                             MacLayer macLayer, SyncMode mode, Type type, long mtuSize) {
        this.id = id;
        this.speed = speed;
        this.ipAddress = ipAddress;
        this.macAddress = macAddress;
        this.physicalMedium = physicalMedium;
        this.macLayer = macLayer;
        this.mode = mode;
        this.type = type;
        this.mtuSize = mtuSize;
    }

    public void dump() { dump(0); }
    public void dump(int tab) {
        Dbg.p(tab, "id:             " + this.id);
        Dbg.p(tab, "speed:          " + this.speed);
        Dbg.p(tab, "ipAddress:      " + this.ipAddress);
        Dbg.p(tab, "macAddress:     " + this.macAddress);
        Dbg.p(tab, "physicalMedium: " + this.physicalMedium);
        Dbg.p(tab, "macLayer:       " + this.macLayer);
        Dbg.p(tab, "mode:           " + this.mode);
        Dbg.p(tab, "type:           " + this.type);
        Dbg.p(tab, "mtuSize:        " + this.mtuSize);
    }

    public String toJson() {

        /*
        {
            "network-topology:node": [
            {
                "node-id": "uni1",
                    "speed": {
                "speed-1G": 1
            },
                "uni:mac-layer": "IEEE 802.3-2005",
                    "uni:physical-medium": "UNI TypeFull Duplex 2 Physical Interface",
                    "uni:mtu-size": 0,
                    "uni:type": "",
                    "uni:mac-address": "b8:27:eb:c9:a9:66",
                    "uni:ip-address": "10.36.0.21",
                    "uni:mode": "Full Duplex"
            }
            ]
        }
        */

        String json =
                "{\n"+
                "   \"network-topology:node\":\n" +
                "   [" +
                "      {\n"+
                "         \"node-id\": \""+ this.getId() +"\",\n"+
                "         \"speed\":\n" +
                "         {\n" +
                "               \""  + this.getSpeed() +  "\": "+"\"1\"\n"+
                "         },\n"+
                "         \"uni:mac-layer\": \""+ this.getMacLayer() +"\",\n"+
                "         \"uni:physical-medium\": \""+ this.getPhysicalMedium() +"\",\n"+
                "         \"uni:mtu-size\": \""+ this.getMtuSize() +"\",\n"+
                "         \"uni:type\": \"\",\n"+
                "         \"uni:mac-address\": \""+ this.getMacAddress() +"\",\n"+
                "         \"uni:ip-address\": \""+ this.getIpAddress() +"\",\n"+
                "         \"uni:mode\": \""+ this.getMode() +"\"\n"+
                "      }\n"+
                "   ]" +
                "}";

        return json;
    }


    public static SvcSpeed cirToSvcSpeed (long cir) {

        // find closest
        SvcSpeed svcSpeed = SvcSpeed.UNASSIGNED;
        if ( cir <= 10000 )
            svcSpeed = SvcSpeed.TEN_MEG;
        else if ( cir <= 100000 )
            svcSpeed = SvcSpeed.HUNDRED_MEG;
        else if ( cir <= 1000000 )
            svcSpeed = SvcSpeed.ONE_GIG;
        else
            svcSpeed = SvcSpeed.TEN_GIG;

        return svcSpeed;
    }

    public static PhysMedium svcSpeedToPhysMedium (SvcSpeed svcSpeed) {


        // just for demo, this really needs to come from host, when hosts are modeled
        switch (svcSpeed) {
            case TEN_MEG:
                return PhysMedium.TEN_BASE_T;
            case HUNDRED_MEG:
                return PhysMedium.HUNDERED_BASE_T;
            case ONE_GIG:
                return PhysMedium.GIG_BASE_T;
            case TEN_GIG:
                return PhysMedium.TEN_GIG_BASE_T;
            default:
                return PhysMedium.UNASSIGNED;
        }
    }

    public static void dumpList(List<Uni> uniList) { dumpList(0, uniList); }
    public static void dumpList(int tab, List<Uni> uniList) {
        int numUni = 0;
        Dbg.p("----- Uni List : [" + uniList.size() + "] elements");
        for (Uni curUni : uniList) {
            numUni++;
            Dbg.p(tab+1, "<Entry " + numUni+">");
            curUni.dump(tab+2);
        }
    }

    // getters & setters

    public String getId() { return id; }
    public void setId(String id) { this.id = id; }

    public SvcSpeed getSpeed() { return speed; }
    public void setSpeed(SvcSpeed speed) { this.speed = speed; }

    public String getIpAddress() { return ipAddress; }
    public void setIpAddress(String ipAddress) { this.ipAddress = ipAddress; }

    public String getMacAddress() { return macAddress; }
    public void setMacAddress(String macAddress) { this.macAddress = macAddress; }

    public PhysMedium getPhysicalMedium() { return physicalMedium; }
    public void setPhysicalMedium(PhysMedium physicalMedium) { this.physicalMedium = physicalMedium; }

    public MacLayer getMacLayer() { return macLayer; }
    public void setMacLayer(MacLayer macLayer) { this.macLayer = macLayer; }

    public SyncMode getMode() { return mode; }
    public void setMode(SyncMode mode) { this.mode = mode; }

    public Type getType() { return type; }
    public void setType(Type type) { this.type = type; }

    public long getMtuSize() { return mtuSize; }
    public void setMtuSize(long mtuSize) { this.mtuSize = mtuSize; }
}