Re: [Ryu-devel] dhcp server with ryu controller

2017-01-10 Thread Luis Zárate
Something like this dhcp rest responder.

The api is:

Set dhcp in a switch PUT /dhcp/add/{dpid}  params
'ipaddress': '192.168.1.1'
'netmask': '255.255.255.0'
'address': '0a:e4:1c:d1:3e:44'
'dns': '8.8.8.8'
'startip':'192.168.1.100'
'endip': '192.168.1.200'
Set static ip in a host PUT /dhcp/host/{dpid} params
'address': '00:00:00:d3:fc:57'
'ipaddress':  '192.168.1.2'
'hostname': 'huehuehue'
'dns': '8.8.8.8' * optional

This file is not complete (needs delete functions) but you will get so util.

2016-12-15 22:34 GMT-06:00 Munther Numan :

> Greeting ,
>
> Dear all,
>
>
>
> I just would like to ask you if I need to add dhcp server in my
> experiment, is any example code for it or there is already  code for dhcp
> server with Ryu controller?
>
> Best Regards
>
> Munther Numan
> Master Student
> Faculty of Engineering
> University Putra Malaysia
>
>
>
>
> 
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> ___
> Ryu-devel mailing list
> Ryu-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>
>


-- 
"La utopía sirve para caminar" Fernando Birri
# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
# Copyright (C) 2013 YAMAMOTO Takashi 
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# a simple ICMP Echo Responder


import json

from ryu.app.wsgi import ControllerBase, WSGIApplication, route
from ryu.base import app_manager
from ryu.controller import ofp_event
from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.lib import addrconv, dpid as dpid_lib
from ryu.lib.packet import dhcp
from ryu.lib.packet import ethernet
from ryu.lib.packet import ipv4
from ryu.lib.packet import packet
from ryu.lib.packet import udp
from ryu.ofproto import ofproto_v1_3
from webob import Response


class DHCPResponder(app_manager.RyuApp):
"""
use example
self.switches = {
'81474781969487': {
'ipaddress': '192.168.1.1',
'netmask': '255.255.255.0',
'address': '0a:e4:1c:d1:3e:44',
'dns': '8.8.8.8',
'hosts': {
'00:00:00:d3:fc:57': {
'hostname': 'huehuehue',
'dns': '8.8.8.8',
'ipaddress':  '192.168.1.2',
}
},
'available_address': [
'192.168.1.10',
'192.168.1.20'
]

}}
"""

OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]
_CONTEXTS = {'wsgi': WSGIApplication}

def __init__(self, *args, **kwargs):
super(DHCPResponder, self).__init__(*args, **kwargs)
self.acks = {}
self.switches = {}
wsgi = kwargs['wsgi']
wsgi.register(DHCPController,
  {'dhcp_server': self})

def get_server_info(self, datapath):
if datapath in self.switches:
ipaddress = addrconv.ipv4.text_to_bin(
self.switches[datapath]['ipaddress'])
netmask = addrconv.ipv4.text_to_bin(
self.switches[datapath]['netmask'])
address = str(self.switches[datapath]['address'])
return ipaddress, netmask, address, str(self.switches[datapath]['ipaddress'])
return None, None, None, None

def get_host_info(self, datapath, hostaddress):
ipaddress = hostname = dns = None
if datapath in self.switches:
if hostaddress in self.acks:
info = self.acks[hostaddress]
return str(info['ipaddress']), str(info['hostname']), info['dns']

if hostaddress in self.switches[datapath]['hosts']:
confhost = self.switches[datapath]['hosts'][hostaddress]
ipaddress = str(confhost['ipaddress'])
hostname = str(confhost['hostname'])
dns = addrconv.ipv4.text_to_bin(confhost['dns'])
if not ipaddress and self.switches[datapath]['available_address']:
ipaddress = str(
self.switches[datapath]['available_address'].pop())
num = ipaddress.split('.')[-1]
hostname = str("machine" + num)
 

[Ryu-devel] dhcp server with ryu controller

2016-12-15 Thread Munther Numan
Greeting ,

Dear all,

 

I just would like to ask you if I need to add dhcp server in my experiment,
is any example code for it or there is already  code for dhcp server with
Ryu controller? 

Best Regards

Munther Numan
Master Student
Faculty of Engineering
University Putra Malaysia

 

--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot___
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel