Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 1 | from unittest import TestCase, main |
| 2 | |
| 3 | from loxi import of13 |
Gamze Abaka | 61c2e98 | 2018-02-14 11:03:36 +0000 | [diff] [blame] | 4 | from ofagent.loxi.of13.instruction import clear_actions |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 5 | from voltha.protos import third_party |
Gamze Abaka | 61c2e98 | 2018-02-14 11:03:36 +0000 | [diff] [blame] | 6 | from ofagent.converter import to_loxi, to_grpc |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 7 | from voltha.core.flow_decomposer import * |
| 8 | |
| 9 | _ = third_party |
| 10 | |
| 11 | |
| 12 | class TestConverter(TestCase): |
| 13 | |
| 14 | def gen_pb_flow_stats(self): |
| 15 | |
| 16 | # device level flows |
| 17 | |
| 18 | flow_stats = [ |
| 19 | mk_flow_stat( |
| 20 | priority=2000, |
| 21 | match_fields=[in_port(2), vlan_vid(4096 + 4000), vlan_pcp(0)], |
| 22 | actions=[pop_vlan(), output(1)] |
| 23 | ), |
| 24 | mk_flow_stat( |
| 25 | priority=2000, |
| 26 | match_fields=[in_port(1), eth_type(0x888e)], |
| 27 | actions=[push_vlan(0x8100), set_field(vlan_vid(4096 + 4000)), |
| 28 | output(2)] |
| 29 | ), |
| 30 | mk_flow_stat( |
| 31 | priority=1000, |
| 32 | match_fields=[in_port(1), eth_type(0x800), ip_proto(2)], |
| 33 | actions=[push_vlan(0x8100), set_field(vlan_vid(4096 + 4000)), |
| 34 | output(2)] |
| 35 | ), |
| 36 | mk_flow_stat( |
| 37 | priority=1000, |
| 38 | match_fields=[in_port(1), eth_type(0x800), ip_proto(17), |
| 39 | udp_src(68), udp_dst(67)], |
| 40 | actions=[push_vlan(0x8100), set_field(vlan_vid(4096 + 4000)), |
| 41 | output(2)] |
| 42 | ), |
| 43 | mk_flow_stat( |
| 44 | priority=1000, |
| 45 | match_fields=[in_port(2), vlan_vid(4096 + 140)], |
| 46 | actions=[pop_vlan(), output(1)] |
| 47 | ), |
| 48 | mk_flow_stat( |
| 49 | priority=500, |
| 50 | match_fields=[in_port(2), vlan_vid(4096 + 1000), metadata(128)], |
| 51 | actions=[pop_vlan(), output(1)] |
| 52 | ), |
| 53 | mk_flow_stat( |
| 54 | priority=500, |
| 55 | match_fields=[in_port(1), vlan_vid(4096 + 128)], |
| 56 | actions=[ |
| 57 | push_vlan(0x8100), set_field(vlan_vid(4096 + 1000)), |
| 58 | output(2)] |
| 59 | ), |
| 60 | mk_flow_stat( |
| 61 | priority=500, |
| 62 | match_fields=[in_port(1), vlan_vid(4096 + 129)], |
| 63 | actions=[ |
| 64 | push_vlan(0x8100), set_field(vlan_vid(4096 + 1000)), |
| 65 | output(2)] |
| 66 | ), |
| 67 | ] + [ |
| 68 | mk_flow_stat( |
| 69 | priority=500, |
| 70 | match_fields=[in_port(2), vlan_vid(4096 + 0)], |
| 71 | actions=[ |
| 72 | set_field(vlan_vid(4096 + 128)), output(1)] |
| 73 | ), |
| 74 | mk_flow_stat( |
| 75 | priority=1000, |
| 76 | match_fields=[ |
| 77 | in_port(1), eth_type(0x800), ipv4_dst(0xe4010102)], |
| 78 | actions=[output(2)] |
| 79 | ), |
| 80 | mk_flow_stat( |
| 81 | priority=1000, |
| 82 | match_fields=[ |
| 83 | in_port(1), eth_type(0x800), ipv4_dst(0xe4010104)], |
| 84 | actions=[output(2)] |
| 85 | ), |
| 86 | mk_flow_stat( |
| 87 | priority=500, |
| 88 | match_fields=[in_port(1), vlan_vid(4096 + 128)], |
| 89 | actions=[set_field(vlan_vid(4096 + 0)), output(2)] |
| 90 | ), |
| 91 | mk_flow_stat( |
| 92 | priority=500, |
| 93 | match_fields=[in_port(2), vlan_vid(0)], |
| 94 | actions=[push_vlan(0x8100), set_field(vlan_vid(4096 + 128)), |
| 95 | output(1)] |
| 96 | ) |
| 97 | |
| 98 | ] |
| 99 | |
| 100 | # logical device level flows |
| 101 | |
| 102 | # Various controller-bound rules |
| 103 | for _in_port in (1, 2): |
| 104 | flow_stats.append(mk_flow_stat( |
| 105 | priority=2000, |
| 106 | match_fields=[in_port(_in_port), eth_type(0x888e)], |
| 107 | actions=[ |
| 108 | push_vlan(0x8100), |
| 109 | set_field(vlan_vid(4096 + 4000)), |
| 110 | output(ofp.OFPP_CONTROLLER) |
| 111 | ] |
| 112 | )) |
| 113 | flow_stats.append(mk_flow_stat( |
| 114 | priority=1000, |
| 115 | match_fields=[eth_type(0x800), ip_proto(2)], |
| 116 | actions=[output(ofp.OFPP_CONTROLLER)] |
| 117 | )) |
| 118 | flow_stats.append(mk_flow_stat( |
| 119 | priority=1000, |
| 120 | match_fields=[eth_type(0x800), ip_proto(17), |
| 121 | udp_src(68), udp_dst(67)], |
| 122 | actions=[output(ofp.OFPP_CONTROLLER)] |
| 123 | )) |
| 124 | |
| 125 | # Multicast channels |
| 126 | mcast_setup = ( |
| 127 | (1, 0xe4010101, ()), |
| 128 | (2, 0xe4010102, (1,)), |
| 129 | (3, 0xe4010103, (2,)), |
| 130 | (4, 0xe4010104, (1, 2)), |
| 131 | ) |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 132 | |
| 133 | group_stats = [] |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 134 | for group_id, mcast_addr, ports in mcast_setup: |
| 135 | # self.lda.update_group_table(mk_multicast_group_mod( |
| 136 | # group_id=group_id, |
| 137 | # buckets=[ |
| 138 | # ofp.ofp_bucket(actions=[ |
| 139 | # pop_vlan(), |
| 140 | # output(port) |
| 141 | # ]) for port in ports |
| 142 | # ])) |
| 143 | flow_stats.append(mk_flow_stat( |
| 144 | priority=1000, |
| 145 | match_fields=[ |
| 146 | in_port(0), |
| 147 | eth_type(0x800), |
| 148 | vlan_vid(4096 + 140), |
| 149 | ipv4_dst(mcast_addr) |
| 150 | ], |
| 151 | actions=[ |
| 152 | group(group_id) |
| 153 | ] |
| 154 | )) |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 155 | group_stats.append(group_entry_from_group_mod( |
| 156 | mk_multicast_group_mod( |
| 157 | group_id=group_id, |
| 158 | buckets=[ |
| 159 | ofp.ofp_bucket(actions=[ |
| 160 | pop_vlan(), |
| 161 | output(port) |
| 162 | ]) for port in ports |
| 163 | ]))) |
| 164 | |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 165 | |
| 166 | # Unicast channels for each subscriber |
| 167 | # Downstream flow 1 for both |
| 168 | flow_stats.append(mk_flow_stat( |
| 169 | priority=500, |
| 170 | match_fields=[ |
| 171 | in_port(0), |
| 172 | vlan_vid(4096 + 1000), |
| 173 | metadata(128) |
| 174 | ], |
| 175 | actions=[pop_vlan()], |
| 176 | next_table_id=1 |
| 177 | )) |
| 178 | # Downstream flow 2 and upsrteam flow 1 for each ONU |
| 179 | for port, c_vid in ((1, 101), (2, 102)): |
| 180 | flow_stats.append(mk_flow_stat( |
| 181 | priority=500, |
| 182 | match_fields=[in_port(0), vlan_vid(4096 + c_vid)], |
| 183 | actions=[set_field(vlan_vid(4096 + 0)), output(port)] |
| 184 | )) |
| 185 | # for the 0-tagged case |
| 186 | flow_stats.append(mk_flow_stat( |
| 187 | priority=500, |
| 188 | match_fields=[in_port(port), vlan_vid(4096 + 0)], |
| 189 | actions=[set_field(vlan_vid(4096 + c_vid))], |
| 190 | next_table_id=1 |
| 191 | )) |
| 192 | # for the untagged case |
| 193 | flow_stats.append(mk_flow_stat( |
| 194 | priority=500, |
| 195 | match_fields=[in_port(port), vlan_vid(0)], |
| 196 | actions=[push_vlan(0x8100), set_field(vlan_vid(4096 + c_vid))], |
| 197 | next_table_id=1 |
| 198 | )) |
| 199 | # Upstream flow 2 for s-tag |
| 200 | flow_stats.append(mk_flow_stat( |
| 201 | priority=500, |
| 202 | match_fields=[in_port(port), vlan_vid(4096 + c_vid)], |
| 203 | actions=[ |
| 204 | push_vlan(0x8100), |
| 205 | set_field(vlan_vid(4096 + 1000)), |
| 206 | output(0) |
| 207 | ] |
| 208 | )) |
| 209 | |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 210 | return (flow_stats, group_stats) |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 211 | |
| 212 | def test_flow_spec_pb_to_loxi_conversion(self): |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 213 | flow_stats, _ = self.gen_pb_flow_stats() |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 214 | for flow_stat in flow_stats: |
| 215 | loxi_flow_stats = to_loxi(flow_stat) |
| 216 | |
alshabib | f4fb268 | 2017-01-12 00:32:56 -0600 | [diff] [blame] | 217 | def test_group_stat_spec_pb_to_loxi_conversion(self): |
| 218 | _, group_stats = self.gen_pb_flow_stats() |
| 219 | for group_stat in group_stats: |
| 220 | loxi_group_stat = to_loxi(group_stat.stats) |
| 221 | |
| 222 | def test_group_desc_spec_pb_to_loxi_conversion(self): |
| 223 | _, group_stats = self.gen_pb_flow_stats() |
| 224 | for group_stat in group_stats: |
| 225 | loxi_group_desc = to_loxi(group_stat.desc) |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 226 | |
Gamze Abaka | 61c2e98 | 2018-02-14 11:03:36 +0000 | [diff] [blame] | 227 | def test_clear_actions_instruction(self): |
| 228 | obj = clear_actions() |
| 229 | ofp_instruction = to_grpc(obj) |
| 230 | self.assertEqual(ofp_instruction.type, 5) |
Zsolt Haraszti | 6692773 | 2017-01-14 16:50:59 -0800 | [diff] [blame] | 231 | |
Zsolt Haraszti | 3578a1c | 2017-01-10 15:29:02 -0800 | [diff] [blame] | 232 | if __name__ == '__main__': |
| 233 | main() |