Code Monkey home page Code Monkey logo

Comments (5)

nickkaranatsios avatar nickkaranatsios commented on September 14, 2024

Yes it is possible to do Trema::Messages::Hello.new( transaction_id: 123 ) but after adding an alias name Hello = Trema::Messages::Hello the following would be also possible Hello.new( transaction_id: 123 ).

from trema-edge.

yasuhito avatar yasuhito commented on September 14, 2024

Hi, I tried the following test code to test the default value of :transaction_id but it fails with a segfault. The test code sends :pack_msg after the Hello message creation so that its :transaction_id is set to default value. Any suggestions?

module Trema
  describe Hello, ".new"
    subject { Hello.new.pack_msg( 0xabc ) }  # 0xabc is for placeholder
    its( :transaction_id ) { should be_unsigned_32bit }
  end
end

The error log:

Trema::Messages::Hello.new
/home/yasuhito/play/trema-edge/ruby/trema/message.rb:34: [BUG] Segmentation fault
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0034 p:---- s:0141 e:000140 CFUNC  :pack_hello_msg
c:0033 p:0049 s:0137 e:000136 METHOD /home/yasuhito/play/trema-edge/ruby/trema/message.rb:34
c:0032 p:0017 s:0131 e:000130 LAMBDA /home/yasuhito/play/trema-edge/spec/trema/messages/hello_spec.rb:25 [FINISH]
c:0031 p:0015 s:0129 e:000125 BLOCK  /home/yasuhito/.rvm/gems/ruby-2.0.0-p0/gems/rspec-core-2.13.1/lib/rspec/core/memoized_helpers.rb:185 [FINISH]
...
```

from trema-edge.

nickkaranatsios avatar nickkaranatsios commented on September 14, 2024

Fixed in http://github.com/trema/trema-edge/commit/a4c8f4553d435a1248cc066ba3d8018bc1bf4dc8
Default attributes can be set either using a lambda block or specifying a default value. Please note that default values can be overwritten if attributes set explicitly.

class Hello
unsigned_int32 :transaction_id, default: lambda { next_transaction_id }
array :version, validate_with: :check_version, default: [ OFP_VERSION ]
end

next_transaction_id calls the get_transaction_id() to return a default value for transaction_id.
For example:

 x = Trema::Hello.new
 => #<Trema::Messages::Hello:0x9c9c058 @transaction_id=1, @version=[4]>

from trema-edge.

yasuhito avatar yasuhito commented on September 14, 2024

Thanks for the quick fix!

I checked the new version with the following simple spec but exitted with assert() failure.

module Trema
  describe Hello, ".new", :nosudo => true do
    subject { Hello.new.pack_msg( 0xabc ) }    
    it_should_behave_like "any Openflow message with default transaction ID"
  end
end

The error message is:

Trema::Messages::Hello.new  it should behave like any Openflow message with default transaction ID
    transaction_id/home/yasuhito/.rvm/gems/ruby-2.0.0-p0/bin/rspec: /home/yasuhito/play/trema-edge/src/lib/trema.c:691: get_trema_name: Assertion `trema_name != ((void *)0)' failed.

from trema-edge.

yasuhito avatar yasuhito commented on September 14, 2024

Sorry I forgot to remove .pack_msg(). Just Hello.new worked fine.

from trema-edge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.