Skip to content

Instantly share code, notes, and snippets.

@yasuhito
Last active December 7, 2015 05:41
Show Gist options
  • Save yasuhito/1aff112df120a5c72e19 to your computer and use it in GitHub Desktop.
Save yasuhito/1aff112df120a5c72e19 to your computer and use it in GitHub Desktop.
# L2 routing path manager
class PathManager < Trema::Controller
def packet_in(_dpid, message)
path = maybe_create_shortest_path(message)
ports = path ? [path.out_port] : @graph.external_ports
ports.each do |each|
send_packet_out(each.dpid,
raw_data: message.raw_data,
actions: SendOutPort.new(each.number))
end
end
# ...
end
# L2 routing switch with virtual slicing.
class SliceableSwitch < PathManager
def packet_in(_dpid, packet_in)
slice = find_slice(packet_in.slice_source,
packet_in.slice_destination(@graph))
if slice
path = maybe_create_shortest_path_in_slice(slice.name, packet_in)
packet_out_to_destination(packet_in, path.out_port) if path
else
flood_to_external_ports(packet_in)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment