ONOS-3749: Show Flow ID and group ID in the flow table as hex values.
Change-Id: If98e0d76876ada2fa1c8d01a1b89230d1919f6c5
Showing
4 changed files
with
109 additions
and
0 deletions
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
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 implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.ui.table.cell; | ||
18 | + | ||
19 | +import org.onosproject.ui.table.CellFormatter; | ||
20 | + | ||
21 | +/** | ||
22 | + * Formats long values as hex strings with a "0x" prefix. | ||
23 | + */ | ||
24 | +public final class HexLongFormatter extends AbstractCellFormatter { | ||
25 | + | ||
26 | + // non-instantiable | ||
27 | + private HexLongFormatter() { } | ||
28 | + | ||
29 | + @Override | ||
30 | + protected String nonNullFormat(Object value) { | ||
31 | + return "0x" + Long.toHexString((Long) value); | ||
32 | + } | ||
33 | + | ||
34 | + /** | ||
35 | + * An instance of this class. | ||
36 | + */ | ||
37 | + public static final CellFormatter INSTANCE = new HexLongFormatter(); | ||
38 | +} |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
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 implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.ui.table.cell; | ||
18 | + | ||
19 | +import org.junit.Test; | ||
20 | +import org.onosproject.ui.table.CellFormatter; | ||
21 | + | ||
22 | +import static org.junit.Assert.assertEquals; | ||
23 | + | ||
24 | +/** | ||
25 | + * Unit tests for {@link HexLongFormatter}. | ||
26 | + */ | ||
27 | +public class HexLongFormatterTest { | ||
28 | + | ||
29 | + private CellFormatter fmt = HexLongFormatter.INSTANCE; | ||
30 | + | ||
31 | + @Test | ||
32 | + public void nullValue() { | ||
33 | + assertEquals("null value", "", fmt.format(null)); | ||
34 | + } | ||
35 | + | ||
36 | + @Test | ||
37 | + public void zero() { | ||
38 | + assertEquals("zero", "0x0", fmt.format(0L)); | ||
39 | + } | ||
40 | + | ||
41 | + @Test | ||
42 | + public void one() { | ||
43 | + assertEquals("one", "0x1", fmt.format(1L)); | ||
44 | + } | ||
45 | + | ||
46 | + @Test | ||
47 | + public void ten() { | ||
48 | + assertEquals("ten", "0xa", fmt.format(10L)); | ||
49 | + } | ||
50 | + | ||
51 | + @Test | ||
52 | + public void twenty() { | ||
53 | + assertEquals("twenty", "0x14", fmt.format(20L)); | ||
54 | + } | ||
55 | + | ||
56 | + @Test | ||
57 | + public void veryBig() { | ||
58 | + assertEquals("very big", "0x7048860f3a38", fmt.format(123456789101112L)); | ||
59 | + } | ||
60 | + | ||
61 | + @Test | ||
62 | + public void maxLong() { | ||
63 | + assertEquals("max long", "0x7fffffffffffffff", fmt.format(Long.MAX_VALUE)); | ||
64 | + } | ||
65 | +} |
... | @@ -30,6 +30,8 @@ import org.onosproject.ui.table.CellFormatter; | ... | @@ -30,6 +30,8 @@ import org.onosproject.ui.table.CellFormatter; |
30 | import org.onosproject.ui.table.TableModel; | 30 | import org.onosproject.ui.table.TableModel; |
31 | import org.onosproject.ui.table.TableRequestHandler; | 31 | import org.onosproject.ui.table.TableRequestHandler; |
32 | import org.onosproject.ui.table.cell.EnumFormatter; | 32 | import org.onosproject.ui.table.cell.EnumFormatter; |
33 | +import org.onosproject.ui.table.cell.HexFormatter; | ||
34 | +import org.onosproject.ui.table.cell.HexLongFormatter; | ||
33 | 35 | ||
34 | import java.util.Collection; | 36 | import java.util.Collection; |
35 | import java.util.List; | 37 | import java.util.List; |
... | @@ -84,6 +86,8 @@ public class FlowViewMessageHandler extends UiMessageHandler { | ... | @@ -84,6 +86,8 @@ public class FlowViewMessageHandler extends UiMessageHandler { |
84 | @Override | 86 | @Override |
85 | protected TableModel createTableModel() { | 87 | protected TableModel createTableModel() { |
86 | TableModel tm = super.createTableModel(); | 88 | TableModel tm = super.createTableModel(); |
89 | + tm.setFormatter(ID, HexLongFormatter.INSTANCE); | ||
90 | + tm.setFormatter(GROUP_ID, HexFormatter.INSTANCE); | ||
87 | tm.setFormatter(SELECTOR, new SelectorFormatter()); | 91 | tm.setFormatter(SELECTOR, new SelectorFormatter()); |
88 | tm.setFormatter(TREATMENT, new TreatmentFormatter()); | 92 | tm.setFormatter(TREATMENT, new TreatmentFormatter()); |
89 | tm.setFormatter(STATE, EnumFormatter.INSTANCE); | 93 | tm.setFormatter(STATE, EnumFormatter.INSTANCE); | ... | ... |
... | @@ -29,6 +29,7 @@ import org.onosproject.ui.table.CellFormatter; | ... | @@ -29,6 +29,7 @@ import org.onosproject.ui.table.CellFormatter; |
29 | import org.onosproject.ui.table.TableModel; | 29 | import org.onosproject.ui.table.TableModel; |
30 | import org.onosproject.ui.table.TableRequestHandler; | 30 | import org.onosproject.ui.table.TableRequestHandler; |
31 | import org.onosproject.ui.table.cell.EnumFormatter; | 31 | import org.onosproject.ui.table.cell.EnumFormatter; |
32 | +import org.onosproject.ui.table.cell.HexFormatter; | ||
32 | 33 | ||
33 | import java.util.Collection; | 34 | import java.util.Collection; |
34 | import java.util.List; | 35 | import java.util.List; |
... | @@ -75,6 +76,7 @@ public class GroupViewMessageHandler extends UiMessageHandler { | ... | @@ -75,6 +76,7 @@ public class GroupViewMessageHandler extends UiMessageHandler { |
75 | @Override | 76 | @Override |
76 | protected TableModel createTableModel() { | 77 | protected TableModel createTableModel() { |
77 | TableModel tm = super.createTableModel(); | 78 | TableModel tm = super.createTableModel(); |
79 | + tm.setFormatter(ID, HexFormatter.INSTANCE); | ||
78 | tm.setFormatter(TYPE, EnumFormatter.INSTANCE); | 80 | tm.setFormatter(TYPE, EnumFormatter.INSTANCE); |
79 | tm.setFormatter(BUCKETS, new BucketFormatter()); | 81 | tm.setFormatter(BUCKETS, new BucketFormatter()); |
80 | return tm; | 82 | return tm; | ... | ... |
-
Please register or login to post a comment