summaryrefslogtreecommitdiff
path: root/regress/usr.sbin
diff options
context:
space:
mode:
authorRafael Zalamena <rzalamena@cvs.openbsd.org>2016-11-16 11:36:04 +0000
committerRafael Zalamena <rzalamena@cvs.openbsd.org>2016-11-16 11:36:04 +0000
commit43e725d079fa0937d7f93e3f8d1b172a0b9c917a (patch)
treebe9ffea6c76539cbb961912f51524cbbdba46a4e /regress/usr.sbin
parentdb0f251ade0e04baf0d15dedf3aeb1d1f3538783 (diff)
Add support for big reads in perl and fix the jumbo test, also remove
message type specific code from OFP encode. ok reyk@
Diffstat (limited to 'regress/usr.sbin')
-rw-r--r--regress/usr.sbin/switchd/OFP.pm19
-rw-r--r--regress/usr.sbin/switchd/args-packet-jumbo.pm4
-rw-r--r--regress/usr.sbin/switchd/run.pl31
3 files changed, 32 insertions, 22 deletions
diff --git a/regress/usr.sbin/switchd/OFP.pm b/regress/usr.sbin/switchd/OFP.pm
index a18606ecf8f..69a2a559250 100644
--- a/regress/usr.sbin/switchd/OFP.pm
+++ b/regress/usr.sbin/switchd/OFP.pm
@@ -95,19 +95,12 @@ sub encode {
$self->{length} = 8 + $datalen;
}
- $pkt = pack("CCnN", $self->{version}, $self->{type},
- $self->{length}, $self->{xid});
-
- if ($self->{version} == 1) {
- # PACKET_IN
- if ($self->{type} == 10) {
- $self->{length} += 10;
- $pkt = pack("CCnNNnnxxa*",
- $self->{version}, $self->{type},
- $self->{length}, $self->{xid}, $self->{buffer_id},
- length($self->{data}),
- $self->{port}, $self->{data});
- }
+ if ($datalen == 0) {
+ $pkt = pack('CCnN', $self->{version}, $self->{type},
+ $self->{length}, $self->{xid});
+ } else {
+ $pkt = pack('CCnNa*', $self->{version}, $self->{type},
+ $self->{length}, $self->{xid}, $self->{data});
}
return ($pkt);
diff --git a/regress/usr.sbin/switchd/args-packet-jumbo.pm b/regress/usr.sbin/switchd/args-packet-jumbo.pm
index 98e9e52583f..5fac4c5e60d 100644
--- a/regress/usr.sbin/switchd/args-packet-jumbo.pm
+++ b/regress/usr.sbin/switchd/args-packet-jumbo.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: args-packet-jumbo.pm,v 1.2 2016/10/05 15:29:26 reyk Exp $
+# $OpenBSD: args-packet-jumbo.pm,v 1.3 2016/11/16 11:36:03 rzalamena Exp $
# Copyright (c) 2016 Reyk Floeter <reyk@openbsd.org>
#
@@ -63,7 +63,7 @@ my $topology = {
"dest_mac" => "ffffffffffff",
"src_ip" => "10.0.0.1",
"dest_ip" => "10.255.255.255",
- "length" => 65475,
+ "length" => 65469,
"count" => 3,
"ofp_response" => main::OFP_T_PACKET_OUT()
}
diff --git a/regress/usr.sbin/switchd/run.pl b/regress/usr.sbin/switchd/run.pl
index e1d5b650b8d..f0a11628138 100644
--- a/regress/usr.sbin/switchd/run.pl
+++ b/regress/usr.sbin/switchd/run.pl
@@ -1,5 +1,5 @@
#!/usr/bin/perl -w
-# $OpenBSD: run.pl,v 1.6 2016/11/16 08:09:26 rzalamena Exp $
+# $OpenBSD: run.pl,v 1.7 2016/11/16 11:36:03 rzalamena Exp $
# Copyright (c) 2016 Reyk Floeter <reyk@openbsd.org>
#
@@ -68,9 +68,20 @@ sub ofp_input {
# Read the body and decode it.
$ofplen = $ofp->{length};
- if ($ofplen > 8) {
- $self->{sock}->recv($pktext, ($ofplen - 8));
- $ofp = NetPacket::OFP->decode($pkt . $pktext) or
+ if (defined($ofplen) && $ofplen > 8) {
+ $ofplen -= 8;
+
+ # Perl recv() only reads 16k at a time, so loop here.
+ while ($ofplen > 0) {
+ $self->{sock}->recv($pktext, $ofplen);
+ if (length($pktext) == 0) {
+ fatal('ofp_input', 'Socket closed');
+ }
+ $ofplen -= length($pktext);
+ $pkt .= $pktext;
+ }
+
+ $ofp = NetPacket::OFP->decode($pkt) or
fatal('ofp_input', 'Failed to decode OFP');
}
ofp_debug('<', $ofp);
@@ -110,12 +121,18 @@ sub ofp_packet_in {
my $pktin = NetPacket::OFP->decode() or fatal($class, "new packet");
my $pkt;
+ $pkt = pack('NnnCxa*',
+ OFP_PKTOUT_NO_BUFFER(), # buffer_id
+ length($data), # total_len
+ $self->{port} || OFP_PORT_NORMAL(), # port
+ OFP_PKTIN_REASON_NO_MATCH(), # reason
+ $data # data
+ );
+
$pktin->{version} = $self->{version};
$pktin->{type} = OFP_T_PACKET_IN();
$pktin->{xid} = $self->{xid}++;
- $pktin->{data} = $data;
- $pktin->{buffer_id} = $self->{count} || 1;
- $pktin->{port} = $self->{port} || OFP_PORT_NORMAL();
+ $pktin->{data} = $pkt;
$pkt = NetPacket::OFP->encode($pktin);
# XXX timeout