Skip to content

Commit 1490de3

Browse files
committed
Merge pull request #214 from tbarbette/PRClickEtherRewriteSpinlock
EtherRewrite and SpinlockPush
2 parents cfa440d + 0565f58 commit 1490de3

File tree

6 files changed

+243
-8
lines changed

6 files changed

+243
-8
lines changed

elements/ethernet/ensureether.hh

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,15 @@ specified by the arguments is prepended to the packet.
2424
2525
=e
2626
27-
Encapsulate packets in an Ethernet header with type
27+
Encapsulate packets without an Ethernet header with type
2828
ETHERTYPE_IP (0x0800), source address 1:1:1:1:1:1, and
2929
destination address 2:2:2:2:2:2:
3030
31-
EtherEncap(0x0800, 1:1:1:1:1:1, 2:2:2:2:2:2)
32-
33-
=n
34-
35-
For IP packets you probably want to use ARPQuerier instead.
31+
EnsureEther(0x0800, 1:1:1:1:1:1, 2:2:2:2:2:2)
3632
3733
=a
3834
39-
EtherEncap */
35+
EtherEncap, EtherRewrite */
4036

4137
class EnsureEther : public Element { public:
4238

elements/ethernet/etherencap.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Return or set the ETHERTYPE parameter.
4444
4545
=a
4646
47-
EtherVLANEncap, ARPQuerier, EnsureEther, StoreEtherAddress */
47+
EtherVLANEncap, ARPQuerier, EnsureEther, StoreEtherAddress, EtherRewrite */
4848

4949
class EtherEncap : public Element { public:
5050

elements/ethernet/etherrewrite.cc

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* EtherRewrite.{cc,hh} -- encapsulates packet in Ethernet header
3+
* Tom Barbette
4+
*
5+
* Copyright (c) 2015 University of Liege
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a
8+
* copy of this software and associated documentation files (the "Software"),
9+
* to deal in the Software without restriction, subject to the conditions
10+
* listed in the Click LICENSE file. These conditions include: you must
11+
* preserve this copyright notice, and you cannot mention the copyright
12+
* holders in advertising related to the Software without their permission.
13+
* The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
14+
* notice is a summary of the Click LICENSE file; the license in that file is
15+
* legally binding.
16+
*/
17+
18+
#include <click/config.h>
19+
#include "etherrewrite.hh"
20+
#include <click/etheraddress.hh>
21+
#include <click/args.hh>
22+
#include <click/error.hh>
23+
#include <click/glue.hh>
24+
CLICK_DECLS
25+
26+
EtherRewrite::EtherRewrite()
27+
{
28+
}
29+
30+
EtherRewrite::~EtherRewrite()
31+
{
32+
}
33+
34+
int
35+
EtherRewrite::configure(Vector<String> &conf, ErrorHandler *errh)
36+
{
37+
if (Args(conf, this, errh)
38+
.read_mp("SRC", EtherAddressArg(), _ethh.ether_shost)
39+
.read_mp("DST", EtherAddressArg(), _ethh.ether_dhost)
40+
.complete() < 0)
41+
return -1;
42+
return 0;
43+
}
44+
45+
inline Packet *
46+
EtherRewrite::smaction(Packet *p)
47+
{
48+
WritablePacket* q = p->uniqueify();
49+
if (q) {
50+
memcpy(q->mac_header(), &_ethh, 12);
51+
}
52+
return q;
53+
}
54+
55+
void
56+
EtherRewrite::push(int, Packet *p)
57+
{
58+
if (Packet *q = smaction(p))
59+
output(0).push(q);
60+
}
61+
62+
Packet *
63+
EtherRewrite::pull(int)
64+
{
65+
if (Packet *p = input(0).pull())
66+
return smaction(p);
67+
else
68+
return 0;
69+
}
70+
71+
void
72+
EtherRewrite::add_handlers()
73+
{
74+
add_data_handlers("src", Handler::h_read, reinterpret_cast<EtherAddress *>(&_ethh.ether_shost));
75+
add_write_handler("src", reconfigure_keyword_handler, "1 SRC");
76+
add_data_handlers("dst", Handler::h_read, reinterpret_cast<EtherAddress *>(&_ethh.ether_dhost));
77+
add_write_handler("dst", reconfigure_keyword_handler, "2 DST");
78+
}
79+
80+
CLICK_ENDDECLS
81+
EXPORT_ELEMENT(EtherRewrite)

elements/ethernet/etherrewrite.hh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#ifndef CLICK_ETHERREWRITE_HH
2+
#define CLICK_ETHERREWRITE_HH
3+
#include <click/element.hh>
4+
#include <clicknet/ether.h>
5+
CLICK_DECLS
6+
7+
/*
8+
=c
9+
10+
EtherRewrite(SRC, DST)
11+
12+
=s ethernet
13+
14+
rewrite source and destination Ethernet address
15+
16+
=d
17+
18+
Rewrite the source and the destination address in the Ethernet header.
19+
The ETHERTYPE is left untouched.
20+
21+
=e
22+
23+
Ensure that source address of all packets passing by is 1:1:1:1:1:1, and
24+
the destination address is 2:2:2:2:2:2:
25+
26+
EtherRewrite(1:1:1:1:1:1, 2:2:2:2:2:2)
27+
28+
=n
29+
30+
This element is useful if there is only one possible nexthop on a given link
31+
(such as for a network-layer transparent firewall), meaning that source and
32+
destination ethernet address will always be the same for a given output.
33+
34+
=h src read/write
35+
36+
Return or set the SRC parameter.
37+
38+
=h dst read/write
39+
40+
Return or set the DST parameter.
41+
42+
=a
43+
44+
EtherEncap, EtherVLANEncap, ARPQuerier, EnsureEther, StoreEtherAddress */
45+
46+
47+
class EtherRewrite : public Element { public:
48+
49+
EtherRewrite() CLICK_COLD;
50+
~EtherRewrite() CLICK_COLD;
51+
52+
const char *class_name() const { return "EtherRewrite"; }
53+
const char *port_count() const { return PORTS_1_1; }
54+
55+
int configure(Vector<String> &, ErrorHandler *) CLICK_COLD;
56+
bool can_live_reconfigure() const { return true; }
57+
void add_handlers() CLICK_COLD;
58+
59+
inline Packet *smaction(Packet *);
60+
61+
Packet *pull(int);
62+
63+
void push(int, Packet *);
64+
65+
private:
66+
67+
click_ether _ethh;
68+
69+
};
70+
71+
CLICK_ENDDECLS
72+
#endif

elements/threads/spinlockpush.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* spinlockpush.{cc,hh} -- element acquires spinlock
3+
* Benjie Chen, Eddie Kohler, Tom Barbette
4+
*
5+
* Copyright (c) 1999-2000 Massachusetts Institute of Technology.
6+
* Copyright (c) 2008 Meraki, Inc.
7+
* Copyright (c) 1999-2013 Eddie Kohler
8+
* Copyright (c) 2015 University of Liege
9+
*
10+
* Permission is hereby granted, free of charge, to any person obtaining a
11+
* copy of this software and associated documentation files (the "Software"),
12+
* to deal in the Software without restriction, subject to the conditions
13+
* listed in the Click LICENSE file. These conditions include: you must
14+
* preserve this copyright notice, and you cannot mention the copyright
15+
* holders in advertising related to the Software without their permission.
16+
* The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
17+
* notice is a summary of the Click LICENSE file; the license in that file is
18+
* legally binding.
19+
*/
20+
21+
#include <click/config.h>
22+
#include <click/router.hh>
23+
#include <click/confparse.hh>
24+
#include <click/error.hh>
25+
#include <click/nameinfo.hh>
26+
#include "spinlockpush.hh"
27+
CLICK_DECLS
28+
29+
int
30+
SpinlockPush::configure(Vector<String> &conf, ErrorHandler *errh)
31+
{
32+
String name;
33+
if (Args(conf, this, errh).read_mp("LOCK", name).complete() < 0)
34+
return -1;
35+
if (!NameInfo::query(NameInfo::T_SPINLOCK, this, name, &_lock, sizeof(Spinlock *)))
36+
return errh->error("cannot locate spinlock %s", name.c_str());
37+
return 0;
38+
}
39+
40+
CLICK_ENDDECLS
41+
EXPORT_ELEMENT(SpinlockPush)

elements/threads/spinlockpush.hh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#ifndef CLICK_SPINLOCKPUSH_HH
2+
#define CLICK_SPINLOCKPUSH_HH
3+
#include <click/element.hh>
4+
#include <click/sync.hh>
5+
CLICK_DECLS
6+
7+
/*
8+
* =c
9+
* SpinlockPush(LOCK)
10+
* =s threads
11+
* acquires a spinlock, push the packets then release the lock
12+
* =d
13+
* Acquires the spinlock named LOCK. LOCK must be defined in a SpinlockInfo
14+
* element. The packet is then pushed through the pipeline and when the
15+
* processing down the push path is done, releases the lock.
16+
*
17+
* =n
18+
* Ensure that a push path will not be traversed by multiple threads at the same
19+
* time while SpinlockAcquire/SpinlockRelease work for any path but do not
20+
* support dropping packets between a SpinlockAcquire and a SpinlockRelease
21+
*
22+
* =a SpinlockInfo, SpinlockAcquire, SpinlockRelease
23+
*/
24+
25+
class SpinlockPush : public Element { public:
26+
27+
SpinlockPush() : _lock(0) {}
28+
~SpinlockPush() {}
29+
30+
const char *class_name() const { return "SpinlockPush"; }
31+
const char *port_count() const { return PORTS_1_1; }
32+
const char *processing() const { return PUSH; }
33+
34+
int configure(Vector<String> &, ErrorHandler *) CLICK_COLD;
35+
36+
void push(int,Packet *p) { _lock->acquire(); output(0).push(p); _lock->release(); }
37+
38+
private:
39+
40+
Spinlock *_lock;
41+
42+
};
43+
44+
CLICK_ENDDECLS
45+
#endif

0 commit comments

Comments
 (0)