Last active
September 13, 2017 12:24
-
-
Save hyhilman/00eaf62d8226eeaac054720bf1f96bd6 to your computer and use it in GitHub Desktop.
simple forwarding switch with pyretic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"application": { | |
"dpctl": "", | |
"ipBase": "10.0.0.0/8", | |
"netflow": { | |
"nflowAddId": "0", | |
"nflowTarget": "", | |
"nflowTimeout": "600" | |
}, | |
"openFlowVersions": { | |
"ovsOf10": "1", | |
"ovsOf11": "0", | |
"ovsOf12": "0", | |
"ovsOf13": "0" | |
}, | |
"sflow": { | |
"sflowHeader": "128", | |
"sflowPolling": "30", | |
"sflowSampling": "400", | |
"sflowTarget": "" | |
}, | |
"startCLI": "1", | |
"switchType": "ovs", | |
"terminalType": "xterm" | |
}, | |
"controllers": [ | |
{ | |
"opts": { | |
"controllerProtocol": "tcp", | |
"controllerType": "remote", | |
"hostname": "c0", | |
"remoteIP": "127.0.0.1", | |
"remotePort": 6633 | |
}, | |
"x": "564.0", | |
"y": "69.0" | |
} | |
], | |
"hosts": [ | |
{ | |
"number": "3", | |
"opts": { | |
"hostname": "kemas", | |
"ip": "10.0.1.1", | |
"nodeNum": 3, | |
"sched": "host" | |
}, | |
"x": "487.0", | |
"y": "368.0" | |
}, | |
{ | |
"number": "1", | |
"opts": { | |
"hostname": "hilman", | |
"ip": "10.0.0.1", | |
"nodeNum": 1, | |
"sched": "host" | |
}, | |
"x": "246.0", | |
"y": "366.0" | |
}, | |
{ | |
"number": "2", | |
"opts": { | |
"hostname": "maxi", | |
"ip": "10.0.2.1", | |
"nodeNum": 2, | |
"sched": "host" | |
}, | |
"x": "731.0", | |
"y": "374.0" | |
} | |
], | |
"links": [ | |
{ | |
"dest": "s3", | |
"opts": {}, | |
"src": "s2" | |
}, | |
{ | |
"dest": "s2", | |
"opts": {}, | |
"src": "s1" | |
}, | |
{ | |
"dest": "hilman", | |
"opts": {}, | |
"src": "s1" | |
}, | |
{ | |
"dest": "kemas", | |
"opts": {}, | |
"src": "s2" | |
}, | |
{ | |
"dest": "maxi", | |
"opts": {}, | |
"src": "s3" | |
} | |
], | |
"switches": [ | |
{ | |
"number": "3", | |
"opts": { | |
"controllers": [ | |
"c0" | |
], | |
"hostname": "s3", | |
"nodeNum": 3, | |
"switchType": "default" | |
}, | |
"x": "725.0", | |
"y": "227.0" | |
}, | |
{ | |
"number": "2", | |
"opts": { | |
"controllers": [ | |
"c0" | |
], | |
"hostname": "s2", | |
"nodeNum": 2, | |
"switchType": "default" | |
}, | |
"x": "541.0", | |
"y": "233.0" | |
}, | |
{ | |
"number": "1", | |
"opts": { | |
"controllers": [ | |
"c0" | |
], | |
"hostname": "s1", | |
"nodeNum": 1, | |
"switchType": "default" | |
}, | |
"x": "326.0", | |
"y": "234.0" | |
} | |
], | |
"version": "2" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyretic.lib.corelib import * | |
from pyretic.lib.std import * | |
from pyretic.lib.query import * | |
subnet1 = '10.0.0.0/24' | |
s1ip1 = IPAddr('10.0.0.1') #hilman | |
s1ip2 = IPAddr('10.0.0.2') | |
subnet2 = '10.0.1.0/24' | |
s2ip1 = IPAddr('10.0.1.1') #kemas | |
s2ip2 = IPAddr('10.0.1.2') | |
subnet3 = '10.0.2.0/24' | |
s3ip1 = IPAddr('10.0.2.1') #maxi | |
s3ip2 = IPAddr('10.0.2.2') | |
hostroute = (match(dstip=s1ip1) >> fwd(2)) +\ | |
(match(dstip=s2ip1) >> fwd(3)) +\ | |
(match(dstip=s3ip1) >> fwd(2)) | |
route = if_(match(switch=1) & ~match(dstip=subnet1), | |
fwd(1), | |
if_(match(switch=3) & ~match(dstip=subnet3), | |
fwd(1), | |
if_(match(switch=2) & ~match(dstip=subnet2), | |
(match(dstip=subnet1) >> fwd(2)) + | |
(match(dstip=subnet3) >> fwd(1)) , | |
hostroute | |
) | |
) | |
) | |
policy = route | |
def main(): | |
print policy | |
return policy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment