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