Skip to content

Instantly share code, notes, and snippets.

View oshothebig's full-sized avatar

Sho Shimizu oshothebig

  • Preferred Networks, Inc.
  • Tokyo, Japan
View GitHub Profile
@oshothebig
oshothebig / gophercon_2014.md
Last active August 29, 2015 14:00
GopherCon 2014
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>proxy.somewhere.com</host>
<port>8080</port>
<username>proxyuser</username>
<password>somepassword</password>
<nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
@oshothebig
oshothebig / ovs-lines.txt
Created March 19, 2012 13:05
Lines of code of Open vSwitch
486 ./datapath/actions.c
578 ./datapath/brcompat_main.c
271 ./datapath/checksum.c
149 ./datapath/checksum.h
84 ./datapath/compat.h
2241 ./datapath/datapath.c
195 ./datapath/datapath.h
74 ./datapath/dp_notify.c
38 ./datapath/dp_sysfs.h
419 ./datapath/dp_sysfs_dp.c
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
OFMessage in = (OFMessage) e.getMessage();
OFMessage out;
switch (in.getType()) {
case HELLO:
break;
case ECHO_REQUEST:
out = fakeSwitch.echoReplyData((OFEchoRequest)in);
ctx.getChannel().write(out);
@oshothebig
oshothebig / SimpleController.java
Created September 3, 2011 12:56
Simple OpenFlow Controller
/*
* Copyright (c) 2011, Sho SHIMIZU
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
@oshothebig
oshothebig / gist:1191031
Created September 3, 2011 11:19
ofp_header
struct ofp_header {
uint8_t version; /* OFP_VERSION. */
uint8_t type; /* One of the OFPT_ constants. */
uint16_t length; /* Length including this ofp_header. */
uint32_t xid; /* Transaction id associated with this packet.
Replies use the same id as was in the request
to facilitate pairing. */
}
OFP_ASSERT(sizeof(struct ofp_header) == 8);
public static void main(String[] args) {
// リピータハブとして動作
MessageListener hub = new MessageListener() {
public void messageReceived(Channel channel, OFMessage msg) {
if (msg.getType() == OFType.PACKET_IN) {
OFPacketIn in = (OFPacketIn)msg;
OFPacketOut out = (OFPacketOut)factory.getMessage(OFType.PACKET_OUT);
out.setBufferId(in.getBufferId());
out.setInPort(in.getInPort());
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
OFMessage out = factory.getMessage(OFType.HELLO);
ctx.getChannel().write(out);
}
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
if (e.getMessage() instanceof OFMessage) {
OFMessage in = (OFMessage)e.getMessage();
log.debug("Message received: message({}), switch({})", in.getType(), ctx.getChannel().getRemoteAddress());
switch (in.getType()) {
case HELLO:
ctx.getChannel().write(factory.getMessage(OFType.FEATURES_REQUEST));
case ECHO_REQUEST:
int xid = in.getXid();
OFMessage out = factory.getMessage(OFType.ECHO_REPLY);
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
// add the binary codec combination first
pipeline.addLast("framer", new LengthFieldBasedFrameDecoder(
MAXIMUM_PACKET_LENGTH, LENGTH_FIELD_OFFSET, LENGTH_FIELD_LENGTH, LENGTH_FIELD_MODIFICATION, 0));
pipeline.addLast("decoder", new OpenFlowDecoder());
pipeline.addLast("encoder", new OpenFlowEncoder());
// add then the business logic