blob: 6ff4bc45c7efe9473323e2301134a0c5940939ab [file] [log] [blame]
import oftest.base_tests as base_tests
from oftest import config
import ofp
from oftest.testutils import *
from oltconstants import *
import copy
import logging
class OltBaseTest(base_tests.SimpleDataPlane):
next_cookie_block = 40
def getCookieBlock(self):
"""Returns the starting value of the next 100 cookies"""
c = self.next_cookie_block
OltBaseTest.next_cookie_block += 100
return c
def resetOlt(self):
"""Reset the OLT into a clean healthy state"""
delete_all_flows(self.controller)
do_barrier(self.controller)
verify_no_errors(self.controller)
def testPacketIn(self, match, parsed_pkt):
delete_all_flows(self.controller)
pkt = str(parsed_pkt)
for of_port in config["port_map"]:
m = copy.deepcopy(match)
m.oxm_list.append(ofp.oxm.in_port(of_port))
request = ofp.message.flow_add(
table_id=test_param_get("table", 0),
cookie=42,
match=m,
instructions=[
ofp.instruction.apply_actions(
actions=[
ofp.action.output(
port=ofp.OFPP_CONTROLLER,
max_len=ofp.OFPCML_NO_BUFFER)])],
buffer_id=ofp.OFP_NO_BUFFER,
priority=1000)
logging.info("Inserting flow sending matching packets to controller")
self.controller.message_send(request)
do_barrier(self.controller)
for of_port in config["port_map"]:
logging.info("PacketInExact test, port %d", of_port)
self.dataplane.send(of_port, pkt)
verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
verify_packets(self, pkt, [])
def processEapolRule(self, in_port, install = True):
match = ofp.match()
match.oxm_list.append(ofp.oxm.eth_type(0x888e))
match.oxm_list.append(ofp.oxm.in_port(in_port))
if install:
request = ofp.message.flow_add(
table_id=test_param_get("table", 0),
cookie=42,
match=match,
instructions=[
ofp.instruction.apply_actions(
actions=[
ofp.action.output(
port=ofp.OFPP_CONTROLLER,
max_len=ofp.OFPCML_NO_BUFFER)])],
buffer_id=ofp.OFP_NO_BUFFER,
priority=1000)
else:
request = ofp.message.flow_delete(
table_id=test_param_get("table", 0),
cookie=42,
match=match,
instructions=[
ofp.instruction.apply_actions(
actions=[
ofp.action.output(
port=ofp.OFPP_CONTROLLER,
max_len=ofp.OFPCML_NO_BUFFER)])],
buffer_id=ofp.OFP_NO_BUFFER,
priority=1000)
logging.info("%s flow sending matching packets to controller" % "Install" if install else "Remove")
self.controller.message_send(request)
do_barrier(self.controller)
def testPacketFlow(self,
s_vlan_id,
c_vlan_id,
onu=None,
verify_blocked_flows=True,
pktlen=96):
incorrectTagPkt = simple_udp_packet(
pktlen=pktlen+4, dl_vlan_enable=True, vlan_vid=s_vlan_id, vlan_pcp=1)
zeroTaggedPkt = simple_udp_packet(
pktlen=pktlen+4, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
untaggedPkt = simple_udp_packet(pktlen=pktlen)
upstreamDoubleTaggedPkt = double_vlan_udp_packet(
pktlen=pktlen+8, dl_vlan_enable=True, c_vlan_vid=c_vlan_id, s_vlan_vid=s_vlan_id,
c_vlan_pcp=0, s_vlan_pcp=0)
inport = onu_port if onu is None else onu
logging.info("Testing s-tag %d, c-tag %d" % (s_vlan_id, c_vlan_id))
# test upstream untagged packet got double tag at OLT
self.dataplane.send(inport, str(zeroTaggedPkt))
verify_packet(self, upstreamDoubleTaggedPkt, olt_port)
# test downstream doubletagged packet got untagged at ONU
self.dataplane.send(olt_port, str(upstreamDoubleTaggedPkt))
if device_type == "pmc":
verify_packet(self, zeroTaggedPkt, inport)
else:
verify_packet(self, untaggedPkt, inport)
if verify_blocked_flows:
# test upstream doubletagged packet got dropped
self.dataplane.send(inport, str(upstreamDoubleTaggedPkt))
verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port)
# test downstream untagged packet got dropped at ONU
self.dataplane.send(olt_port, str(untaggedPkt))
verify_no_packet(self, untaggedPkt, inport)
# test upstream icorrectly tagged packet; should get dropped
self.dataplane.send(inport, str(incorrectTagPkt))
verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port)
def testSustainedPacketFlow(self, s_vlan_id, c_vlan_id, number_of_roundtrips=10, onu=None):
for i in xrange(number_of_roundtrips):
print "loop %d" % i
self.testPacketFlow(s_vlan_id, c_vlan_id, onu=onu, verify_blocked_flows=False)
def installDoubleTaggingRules(self, s_vlan_id, c_vlan_id, cookie=42, onu = None):
inport = onu_port if onu is None else onu
# upstream flow rule
match = ofp.match()
match.oxm_list.append(ofp.oxm.in_port(inport))
if device_type == "cpqd":
match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_NONE))
actions = [
ofp.action.push_vlan(ethertype=0x8100),
ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)),
ofp.action.set_field(ofp.oxm.vlan_pcp(0))
]
else: # "pmc", "normal"
match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT))
match.oxm_list.append(ofp.oxm.vlan_pcp(value=0))
actions = [
ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
]
cookie += 1
# push inner vlan (c-vlan) for upstream
request = ofp.message.flow_add(
table_id=test_param_get("table", 0),
cookie=cookie,
match=match,
instructions=[
ofp.instruction.apply_actions(actions=actions),
ofp.instruction.goto_table(1)],
buffer_id=ofp.OFP_NO_BUFFER,
priority=1000)
self.controller.message_send(request)
do_barrier(self.controller)
verify_no_errors(self.controller)
# push outer vlan (s-vlan) for upstream
match = ofp.match()
match.oxm_list.append(ofp.oxm.in_port(inport))
match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
match.oxm_list.append(ofp.oxm.vlan_pcp(0))
cookie += 1
request = ofp.message.flow_add(
table_id=test_param_get("table", 1),
cookie=cookie,
match=match,
instructions=[
ofp.instruction.apply_actions(
actions=[
ofp.action.push_vlan(ethertype=0x8100),
ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)),
ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
ofp.action.output(port=olt_port)]),
],
buffer_id=ofp.OFP_NO_BUFFER,
priority=1000)
self.controller.message_send(request)
do_barrier(self.controller)
verify_no_errors(self.controller)
cookie += 1
# strip outer vlan (s-vlan) for downstream
match = ofp.match()
match.oxm_list.append(ofp.oxm.in_port(olt_port))
match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id))
match.oxm_list.append(ofp.oxm.vlan_pcp(0))
request = ofp.message.flow_add(
table_id=test_param_get("table", 0),
cookie=cookie,
match=match,
instructions=[
ofp.instruction.apply_actions(
actions=[ofp.action.pop_vlan()]),
ofp.instruction.goto_table(1)],
buffer_id=ofp.OFP_NO_BUFFER,
priority=1000)
self.controller.message_send(request)
do_barrier(self.controller)
verify_no_errors(self.controller)
# rewrite inner vlan (c-vlan) to default (0) for downstream
match = ofp.match()
match.oxm_list.append(ofp.oxm.in_port(olt_port))
match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
match.oxm_list.append(ofp.oxm.vlan_pcp(0))
cookie += 1
request = ofp.message.flow_add(
table_id=test_param_get("table", 1),
cookie=cookie,
match=match,
instructions=[
ofp.instruction.apply_actions(
actions=[
ofp.action.pop_vlan(),
ofp.action.output(port=inport)])
],
buffer_id=ofp.OFP_NO_BUFFER,
priority=1000)
self.controller.message_send(request)
do_barrier(self.controller)
verify_no_errors(self.controller)