Note that there are some explanatory texts on larger screens.

plurals
  1. POWarning: Data truncated for column 'src_address' at row 1
    primarykey
    data
    text
    <pre><code>from pox.core import core import pox.openflow.libopenflow_01 as of import re import datetime import time from sqlalchemy import create_engine, ForeignKey from sqlalchemy import Column, Date, Integer, String from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship, backref from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.sql.expression import exists log = core.getLogger() engine = create_engine('mysql://root@192.168.129.139/nwtopology', echo=False) Base = declarative_base() Session = sessionmaker(bind=engine) session = Session() class SourcetoPort(Base): """""" __tablename__ = 'source_to_port' id = Column(Integer, primary_key=True) port_no = Column(Integer) src_address = Column(String(16),index=True) #----------------------------------------- def __init__(self, src_address,port_no): """""" self.src_address = src_address self.port_no = port_no #create tables Base.metadata.create_all(engine) def act_like_switch (self, packet, packet_in): """ Implement switch-like behavior. """ # Learn the port for the source MAC #print "RECIEVED FROM PORT ",packet_in.in_port , "SOURCE ",packet.src ,"DEST" , packet.dst self.mac_to_port[packet.src]=packet_in.in_port r_res = session.query(SourcetoPort).filter_by(src_address=str(packet.src)).first() if r_res is None: print "inserting an entry" start = time.time() entry = SourcetoPort(src_address=str(packet.src) , port_no=packet_in.in_port) #add the record to the session object session.add(entry) #add the record to the session object session.commit() end = time.time() elapsed = end - start print "elapsed insert time ",elapsed else: print "entry already present" </code></pre> <p>I have a network where I am sending packets from one host to another.The expected behaviour is that the first time the src_address,port pair should be inserted into the sql database and thereafter it should only do retrieve operation.I have tested this functionlity working correctly with a local database using sqlite.Then I shifted to a remote database using mysql.</p> <p>Now I find that </p> <pre><code>if r_res is None: </code></pre> <p>is always true,meaning </p> <p>r_res = session.query(SourcetoPort).filter_by(src_address=str(packet.src)).first()</p> <p>is always failing.</p> <p>I suspect this has something to do with some wrong query / add for mysql that is different from that for sqlite.</p> <pre><code>It did print out a warning as below when inserting an entry. /usr/lib/python2.7/dist-packages/sqlalchemy/engine/default.py:330: Warning: Data truncated for column 'src_address' at row 1 cursor.execute(statement, parameters) </code></pre> <p>I can't figure out what exactly seems to be the problem.</p> <p>Based on the comments I have printed out the size of src_address that I am trying to insert.</p> <pre><code> print 'length of src addreess',len(str(packet.src)) it prints 17 </code></pre> <p>and I have increased the size of src_address to 17,32 and 64.Still I get the same error</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload