BGP AS numbers?

We have 50+ sites on our MPLS network. All are connected quite successfully and all have a completely individual private AS number eg router bgp 65001
We are about to bring a new site online and our telco provider has given us the details but this time with an AS number that we have on another site.
When I spotted this and pointed it out, our provider said that it was ok for our sites to have the same AS number and they didn't have to be unique to each site.
Is this correct?

Hi Louis,
It might work, it all depends on the kind of solution you've got in your network.
We all know that BGP loop prevention mechanism works checking the AS-path of the packet and it compares it with your AS. If any of the AS written in the AS-path match with your AS the update will be discarded and your router will not learn that update.
This might represent some problems with LantoLan communications.
According to that, you can use some features that BGP have:
BGP allowas-in: (http://www.cisco.com/c/en/us/support/docs/ip/border-gateway-protocol-bgp/112236-allowas-in-bgp-config-example.html)
BGP as-override: (https://supportforums.cisco.com/document/87671/understanding-bgp-override-feature)
You can use any of them depending on your network needs.
I Hope this information could be useful to you.
Sorry about my english.

Similar Messages

  • BGP peers with same AS number

    Hi All,
    As in the network topology attached (replica of actual network), I would like to know if there is any way that routes received from PE-RTR1 in CE-RTR can be advertised to PE-RTR2 and vice versa, so that PE-RTR1 & PE-RTR2 can reach each other.
    Routing protocol used between PE-RTR1 & CE and PE-RTR2 & CE is BGP.
    The issue seems to be due to same AS number of PE-RTR1 & PE-RTR2. It might not be possible to change AS numbers defined. Is there any way to overcome this situation?
    Thanks in advance..
    Regards,
    Nagabhushan

    I read that a bit too quickly.
    If you're connecting your locations via the ISP and they all use the same AS, they'll all need the statement I mentioned in my previous comment. If you already have communication between them via the ISP, then this command is probably already there.
    If you're connecting everything via fibre to the primary location, you can just peer with the other locations using the same AS and you'll be fine... though there are some considerations if you're redistributing BGP into an internal routing protocol.
    In your current configuration, is each location seeing the networks from the other sites propagating from the ISP via BGP?

  • Multiple BGP instances

    Hi All,
    We have a central location (can be called as HUB location) to which multiple branch locations connect over MPLS connectivity. Currenlty we are using non-Cisco device to terminate MPLS links in central location. CE-PE routing protocol used is BGP.
    Since there are multiple MPLS service providers are involved and each of them use different AS numbers, we made use of virtual routing instances to use multiple BGP instances.
    In future, we are planning to buy Cisco routers to terminate these MPLS links. As per our findings, Cisco ISR 4451-X suffice our requirement in terms of bandwidth, number of sessions etc...
    However, we are not able to find any document as such, which gives information of multiple BGP instances configuration or virtual router instance configuration.
    So, we would like to know whether Cisco 4451-X ISR supports multiple BGP instances?
    Also it would be helpful if anyone can help to know whether is there any possibility to cluster 4451-X routers or any other way to build redundancy in terms of hardware.
    Regards,
    Nagabhushan

    Unfortunately there seems to be little documentation on 4451-x so far. It is part of the ISR G2 family though and I think it is running IOS-XE.
    I would expect it to run same features as all ISR meaning that using VRFs should be no issue. You can then peer BGP within the VRFs. You could probably even run MPLS on it if you wanted to.
    I don't believe it has any clustering functionality. Hopefully someone from Cisco can clarify with more information.
    Daniel Dib
    CCIE #37149
    Please rate helpful posts.

  • BGP load sharing with bandwidth

    We are running eBGP between two routers. We had a 250 M PVC between the two routers on OSM STM4 ATM interface. We need to increase the B/W between the two routers to 350M, but because there's a limitation on the PVC size for the OSM STM4 ATM card (Max. size of the PVC is 300M), so we created new PVC between the two routers on the same circuits (and of course the same interfaces). Now I need to enable the load sharing between the two routers taking the PVC B/W in consideration.. So I prepared this config, is it right and full? Or Am I missing anything here..
    RouterA:
    Router bgp 100
    Neighbor 10.1.1.1 remote-as 200 (10.1.1.1 is loop back address fro Router B)
    Neighbor 10.1.1.1 ebgp-multihop
    bgp dmzlink-bw
    neighbor 10.1.1.1 dmzlink-bw
    neighbor 10.1.1.1 send-community both
    maximum-paths ebgp 2
    RouterB:
    Router bgp 100
    Neighbor 10.10.1.1 remote-as 200 (10.10.1.1 is loop back address fro Router A)
    Neighbor 10.10.1.1 ebgp-multihop
    neighbor 10.10.1.1 send-community both
    bgp dmzlink-bw
    neighbor 10.10.1.1 dmzlink-bw
    maximum-paths ebgp 2

    I implmented these changes but did not work, becuase the command neighbor 10.10.1.1 dmzlink-bw is not supported with multihop (Neighbor 10.10.1.1 ebgp-multihop).
    I removed the loopback BGP neighbor and created 2 BGP neighbors with the directly connected interfaces IP's and applied same configuration and now it works fine.. Here's show Ip route (Ip's and AS numbers have been chnaged)
    R1#sh ip ro 10.10.0.1
    Routing entry for 10.10.0.0/20
    Known via "bgp xxxxx", distance 20, metric 10
    Tag xxxx, type external
    Last update from x.x.x.x 00:00:24 ago
    Routing Descriptor Blocks:
    * x.x.x.x, from x.x.x.x, 00:00:24 ago
    Route metric is 10, traffic share count is 240
    AS Hops 1
    Route tag xxxxx
    y.y.y.y, from y.y.y.y, 00:00:24 ago
    Route metric is 10, traffic share count is 83
    AS Hops 1
    Route tag xxxx
    notice the traffic share count
    traffic share count is 240 (for peer #1)
    traffic share count is 83 (for peer # 2)
    It's almost 3:1

  • BGP Filtering

    Is there a way in BGP to use an inbound filter list to select prefixes from only certain ASs but always accept a certain prefix no matter what AS path it has?
    Scenario:  We have two upstream providers and are accepting only certain AS paths from each.  In addition, both providers are sending 0.0.0.0/0.  We filter that route from our secondary provider but have a floating static to 0.0.0.0/0 in case our default provider goes down.  Our default provider used to send the route with only their AS in the path but something changed where they are now advertising the default route which they are receiving from one of their upstream providers so the AS path changed.  At this point, we filtered the default route out because it didn't match our AS filter.  I can add that particular AS to our filter but if it changes again, we will be in the same boat.  I believe that the only way for this to work now is to accept all prefixes and AS paths from this provider and then mark any route learned from our secondary provider with a better preference.  The only other way would be to create a static default route that points to a prefix in their network and hope that that network never went down which I don't want to do.

    Thanks for the reply.  No we do not have a route map filtering AS paths, we have an as-path access-list using regular expressions bound via a filter-list statement to filter AS paths.  This is set to allow only paths with our upstream provider and also paths with two unique AS numbers (our upstream provider and a few select ASs).  We use an as-path access-list since it is easier to allow those paths which contain two AS numbers (although any number of repeats, ie:
    ip as-path access-list 1 permit ^xxxxx(_xxxxx)*_yyyyy(_yyyyy)*$
    I supposed we could bind it into the route-map that is bound to that neighbor but the route map is doing something different.  It was cleaner to use the route-map to do one thing and the filter-list to do the other because if we combine them together we'll have to create some nests.  However this would probably be better than accepting all routes when we don't really need them.

  • Enabl BGP between PE-CE when PE and CE are in same AS

    We have BGP enable PE-CE setup in MPLS network. Customer A has branches with unique AS numbers.
    We connected our PE routers via BGP with customer CE. Issue is Customer's Head Office AS number is equal to our AS number .
    We are telecom provider having same AS for iBGP in our MPLS network.
    Can you say how connect customer AS (Headoffice) with our PE router when PE and CE are in same AS

    No, you cannot use it only at one side otherwise one side will try to do an iBGP peering while the other will try to do an eBGP peering. And anyway, IOS is smart enough to refuse the local-as command if the remote-as matches its local AS.

  • Enable BGP between PE-CE when PE and CE are in same AS

    We have BGP enable PE-CE setup in MPLS network. Customer A has branches with unique AS numbers.
    We connected our PE routers via BGP with customer CE. Issue is Customer's Head Office AS number is equal to our AS number .
    We are telecom provider having same AS for iBGP in our MPLS network.
    Can you say how connect customer AS (Headoffice) with our PE router when PE and CE are in same AS

    AS Override?

  • Can BGP be used like EIGRP / OSPF?

    Can BGP be used like EIGRP / OSPF? Can some one explain?

    Disclaimer
    The Author of this posting offers the information contained within this posting without consideration and with the reader's understanding that there's no implied or expressed suitability or fitness for any purpose. Information provided is for informational purposes only and should not be construed as rendering professional advice of any kind. Usage of this posting's information is solely at reader's own risk.
    Liability Disclaimer
    In no event shall Author be liable for any damages whatsoever (including, without limitation, damages for loss of use, data or profit) arising out of the use or inability to use the posting's information even if Author has been advised of the possibility of such damage.
    Posting
    As Peter described, normally you wouldn't use BGP in place of an IGP like EIGRP or OSPF.
    However, if you're a masochist, you could.
    For example, if all your routers were connected by p2p links, you could configure each router in its own AS and run them as eBGP peers.
    What Peter was alluding to, normally interior BGP peers run as iBGP peers, but then each requires a connection to every other peer (full mesh).  (There's also BGP route reflectors or BGP confederations, which limit the need for interior iBGP peering to all other iBGP routers, but neither deals with how the iBGP routers "know" how to route to their required peers.)  Normally an IGP protocol is used to provide reachability, but you could do the same with static routes.  Of course, whether you have an IGP or use static routes that maps out the whole interior topology they both beg the question of why also then have iBGP too (if being used just for the interior topology).
    There's a limit to the number of AS numbers, especially if using just the private range, so you could combine the two approaches, such as having small clusters of iBGP peers (maybe 2 or 3) which eBGP peer to other clusters.
    If you did go to all the trouble, you would then find that BGP will likley converge  slower than most IGPs and unless you do some manual policy configuration, BGP won't path select much better than RIP.
    What BGP does well is handle massive route tables (like the Internet) and allow very sophiscated (manual) routing policies.  However, both are usually not as desirable for an IGP.

  • BGP and auto-summary enabled or disabled with "network" command

    http://www.cisco.com/en/US/tech/tk365/technologies_q_and_a_item09186a00800949e8.shtml#five
    I just modified the below quoted by adding numbers
    My understanding is this:
    A- I hope my numbering to the quoted above is right ,,,I numbered it to be easy to point to it.
    B- What does it mean by locally originated, does it mean within AS ?
    1- auto-summary is enabled it summarizes the locally originated BGP networks to their classfull boundaries without caring to check if there are any entry in IGP routing table,,,,Am I right ?
    2- auto-summary is disabled, the routes introduced locally into the BGP table are not summarized to their classfull boundaries, without caring to check if there are any entry in IGP routing table,,,,Am I right ?
    3- I could not match his example with his explanation
    4- It is obvious.

    Thanks hritter
    I think you forgot to answer this :
    1- Does that mean with "no auto-summary" we do not care about the exact match
    The author says:
    "3- When a subnet exists in the routing table and the following three conditions are satisfied, then any subnet of that classfull network in the local routing table will prompt BGP to install the classfull network into the BGP table.
    * Classfull network statement for a network in the routing table
    * Classfull mask on that network statement
    * Auto-summary enabled "
    Correct my understanding to the above quoted
    The author says: For example, if the subnet in the routing table is 75.75.75.0 mask 255.255.255.0 {match the above quoted : “When a subnet exists in the routing table”}.
    The author says : and you configure network 75.0.0.0 under the router bgp command (for my understanding it does not match the above quoted first comdition : “Classfull network statement for a network in the routing table”},,,,,,,he says 75.0.0.0 under bgp table and the above quoted says under routing table (IGP table)

  • BGP NSF

    Hello,
    1. Is NSF supported for BGP routing protocol? If so how to enable that?
    2. Can we configure both NSF and NSR for a same instance of IGP routing protocol? If so, which will have top priority(whether NSF or NSR)?
    Thanks
    Hari

    Hi Hari,
    because the a9k provides for a total distributed architecture, whereby the control plane is separated from teh forwarding, there is natively already NSF, so for that you dont have to configure anything.
    You can read up more on that topic if you like when you google asr9000 route scale architecture.
    NSR, that is bascially to keep a peering alive, while the standby sending the actual TCP packets (to keep the seq numbers in sync) is something that you configure separately via:
    rotuer bgp 100
    nsr
    Assisting in NSF can be the fucntionality of graceful restart (to maintain the session before declaring it down), and NSF is also implemented by nature via the functionality of SSO (stateful switchover).
    The concept of NSR is tricky and important, I have a write up for you here:
    The NSR implementation in XR relies on the use of the Standby RP. If the
    process were to fail/crash on the Active RP, unless control is passed to the
    Standby RP, NSR operation will not work - in effect it will then revert back to
    either Graceful-restart (if enabled) or a full process restart (peer down/adj
    down etc.). The process on the Active RP cannot recover state from the Standby
    RP. If you were to have a situation where the Active RP were to crash, then NSR
    functionality will kick-in as control will be passed to the Standby RP.
    The question is, do you only want NSR to occur in the event of an RP failure
    (which should be a rare occurrence)? If the answer is 'yes', then do no enable
    the configuration 'nsr process-failures switchover'. If the answer is 'no' and
    the customer understand that an RP failover is expected in the circumstances,
    then enable 'nsr process-failures switchover'. For some customer, the very idea
    of an RP failover is just 'bad' - for others, they are comfortable with this
    form of operation.
    There are only a few SPs using NSR today, since for many, the key driver has
    been BGP NSR which was only delivered in rls 3.8.0. We do have customers who
    are in service with NSR for OSPF and LDP and BGP - we have a good number of
    customers who are using ISIS with NSF CISCO (which is actually NSR), which was
    delivered back in rls 3.3.x. They do use the 'nsr process-failures switchover'
    since the RP failover is considered to be too rare an event.
    Without 'nsr process-failures switchover' enabled, NSR will only come into
    effect should the RP crash or an RP failover be manually triggered.
    Enabling this config will result in a failover being initiated if BGP, TCP, LDP
    or OSPF were to crash. Since an FO is immediately triggered to preserve NSR, a
    core-dump of the crashed process will not be available. If diagnosing such a
    crash is more important for the customer, then this knob should not be turned
    on.
    xander

  • BGP AS number

    Hi Guys,
    Let's say I have 2 CEs that use different VRFs (VRF light), can I use only one BGP AS number to peer with different PEs? or should the AS number be configured per VRF?
    Thanks,

    Hi,
    can I use only one BGP AS number to peer with different PEs?
    Not only you can - you have to. Regardless of presence and count of VRFs, you can start only a single BGP process in your configuration. It is, to my best knowledge, not possible to configure AS numbers on a per-VRF basis in BGP.
    There is an option of pretending that your BGP ASN is different than the true one, activated using the neighbor local-as command. However, this is not a typical use case for this command, and if you can avoid it, you should.
    Best regards,
    Peter

  • BGP AS Migration

    Hi all.
    I've just run into the following problem when configuring Dual Autonomous System Support for BGP.
    We handle 2 AS numbers that we intend to merge. 
    R1 has the following config:
    router bgp 10
    no bgp default ipv4-unicast
    bgp log-neighbor-changes
    neighbor 192.168.0.2 remote-as 10
    address-family ipv4
      neighbor 192.168.0.2 activate
      no auto-summary
      no synchronization
    exit-address-family
    R2 is located in a different AS (As20) and we try to pretend it is in AS10 ( from R1 perspective).  R2 config is as follows:
    router bgp 20
    no bgp default ipv4-unicast
    bgp log-neighbor-changes
    neighbor 192.168.0.1 remote-as 10
    neighbor 192.168.0.1 local-as 10 no-prepend replace-as
    address-family ipv4
      neighbor 192.168.0.1 activate
      no auto-summary
      no synchronization
    exit-address-
    It seems that BGP session is properly established with this config.  However as soon as we add a network command to originate a given prefix the bgp session goes down. We see the following when running a debug ip bgp:
    *Mar  1 00:08:30.643: %BGP-3-NOTIFICATION: received from neighbor 192.168.0.1 3/3 (update missing required attributes) 0 bytes
    *Mar  1 00:08:30.643: BGP: 192.168.0.1 went from Established to Closing *Mar  1 00:08:30.643: %BGP-3-NOTIFICATION: received from neighbor 192.168.0.1 3/3 (update missing required attributes) 0 bytes
    *Mar  1 00:08:30.643: BGP: 192.168.0.1 went from Established to Closing
    Then the BGP session is established again but it goes down inmediately.....
    I haven't a clue about where the problem might be.  Any suggestion?
    Thanks
    Flo.

    Hi Riccardo
    Thanks for your comments.
    I've just run the ip bgp events/updates debug and this is what I can see in both sides:
    R1  ( the router that receives the update)
    *Mar  1 00:06:38.803: BGP: 192.168.0.2 Update missing attributes, flags 0x7
    *Mar  1 00:06:38.807: BGP: 192.168.0.2 reset due to BGP Notification sent
    *Mar  1 00:06:38.807: %BGP-5-ADJCHANGE: neighbor 192.168.0.2 Down BGP Notification sent
    *Mar  1 00:06:38.807: %BGP-3-NOTIFICATION: sent to neighbor 192.168.0.2 3/3 (update missing required attributes) 0 bytes
    R1# FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF 0035 0200 0000 1940 0101 0040 0204 0201 000A 4003 04C0 A800 0280 0404 0000 0000 2002 0202 02
    *Mar  1 00:06:38.927: BGP: service reset requests
    *Mar  1 00:06:38.927: BGP: service reset requests
    R2(config)#router bgp 20
    R2(config-router)#net
    R2(config-router)#network 2.2.2.2 mask
    R2(config-router)#network 2.2.2.2 mask 255.255.255.255
    R2(config-router)#
    *Mar  1 00:06:38.179: BGP(0): route 2.2.2.2/32 up
    *Mar  1 00:06:38.179: BGP(0): nettable_walker 2.2.2.2/32 route sourced locally
    *Mar  1 00:06:38.183: BGP(0): 192.168.0.1 send UPDATE (format) 2.2.2.2/32, next 192.168.0.2, metric 0, path Local
    *Mar  1 00:06:38.251: %BGP-3-NOTIFICATION: received from neighbor 192.168.0.1 3/3 (update missing required attributes) 0 bytes
    *Mar  1 00:06:38.255: BGP: 192.168.0.1 reset due to BGP Notification received
    *Mar  1 00:06:38.255: %BGP-5-ADJCHANGE: neighbor 192.168.0.1 Down BGP Notification received
    R2(config-router)#
    *Mar  1 00:06:38.255: BGP: service reset requests
    *Mar  1 00:06:38.259: BGP: service reset requests
    *Mar  1 00:06:38.259: BGP: service reset requests
    *Mar  1 00:06:38.259: BGP: service reset requests
    R2(config-router)#
    *Mar  1 00:06:39.675: BGP: Regular scanner event timer
    *Mar  1 00:06:39.675: BGP: Performing BGP general scanning
    *Mar  1 00:06:39.675: BGP(0): scanning IPv4 Unicast routing tables
    *Mar  1 00:06:39.675: BGP(IPv4 Unicast): Performing BGP Nexthop scanning for general scan
    *Mar  1 00:06:39.675: BGP(0): Future scanner version: 5, current scanner version: 4
    *Mar  1 00:06:39.679: BGP(2): scanning VPNv4 Unicast routing tables
    *Mar  1 00:06:39.679: BGP(VPNv4 Unicast): Performing BGP Nexthop scanning for general scan
    *Mar  1 00:06:39.679: BGP(2): Future scanner version: 5, current scanner version: 4
    *Mar  1 00:06:39.679: BGP(4): scanning IPv4 Multicast routing tables
    *Mar  1 00:06:38.803: BGP: 192.168.0.2 Update missing attributes, flags 0x7
    *Mar  1 00:06:38.807: BGP: 192.168.0.2 reset due to BGP Notification sent
    *Mar  1 00:06:38.807: %BGP-5-ADJCHANGE: neighbor 192.168.0.2 Down BGP Notification sent
    *Mar  1 00:06:38.807: %BGP-3-NOTIFICATION: sent to neighbor 192.168.0.2 3/3 (update missing required attributes) 0 bytes
    R1# FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF 0035 0200 0000 1940 0101 0040 0204 0201 000A 4003 04C0 A800 0280 0404 0000 0000 2002 0202 02
    *Mar  1 00:06:38.927: BGP: service reset requests
    *Mar  1 00:06:38.927: BGP: service reset requests
    R2 (router that is configured with the "local-as no-prepend replace-as").  As soon as I configured the network 2.2.2.2 mask 255.255.255.255 command to announce a loopback interface to the peer, everything is triggered. These are the debug messages:
    R2(config)#router bgp 20
    R2(config-router)#net
    R2(config-router)#network 2.2.2.2 mask
    R2(config-router)#network 2.2.2.2 mask 255.255.255.255
    R2(config-router)#
    *Mar  1 00:06:38.179: BGP(0): route 2.2.2.2/32 up
    *Mar  1 00:06:38.179: BGP(0): nettable_walker 2.2.2.2/32 route sourced locally
    *Mar  1 00:06:38.183: BGP(0): 192.168.0.1 send UPDATE (format) 2.2.2.2/32, next 192.168.0.2, metric 0, path Local
    *Mar  1 00:06:38.251: %BGP-3-NOTIFICATION: received from neighbor 192.168.0.1 3/3 (update missing required attributes) 0 bytes
    *Mar  1 00:06:38.255: BGP: 192.168.0.1 reset due to BGP Notification received
    *Mar  1 00:06:38.255: %BGP-5-ADJCHANGE: neighbor 192.168.0.1 Down BGP Notification received
    R2(config-router)#
    *Mar  1 00:06:38.255: BGP: service reset requests
    *Mar  1 00:06:38.259: BGP: service reset requests
    *Mar  1 00:06:38.259: BGP: service reset requests
    *Mar  1 00:06:38.259: BGP: service reset requests
    R2(config-router)#
    *Mar  1 00:06:39.675: BGP: Regular scanner event timer
    *Mar  1 00:06:39.675: BGP: Performing BGP general scanning
    *Mar  1 00:06:39.675: BGP(0): scanning IPv4 Unicast routing tables
    *Mar  1 00:06:39.675: BGP(IPv4 Unicast): Performing BGP Nexthop scanning for general scan
    *Mar  1 00:06:39.675: BGP(0): Future scanner version: 5, current scanner version: 4
    *Mar  1 00:06:39.679: BGP(2): scanning VPNv4 Unicast routing tables
    *Mar  1 00:06:39.679: BGP(VPNv4 Unicast): Performing BGP Nexthop scanning for general scan
    *Mar  1 00:06:39.679: BGP(2): Future scanner version: 5, current scanner version: 4
    *Mar  1 00:06:39.679: BGP(4): scanning IPv4 Multicast routing tables
    Regarding the IOS, I'm currently using  Version 12.4(25d),
    Cheers!
    Flo.

  • Subnet advertisement with different BGP peer

    Hi expert,
    This might be a stupid a question. But just bear with me. Am actually a noob in BGP, so your help is greatly appreciated.
    I have the below scenario:
    Three providers
    P1 subnets: 1.1.1.0/24, 2.2.2.0/24
    P2 subnets:  3.3.3.0/24 4.4.4.0/24
    P3 subnets: 5.5.5.0/24 6.6.6.0/24
    Lets say i want to advertise subnets 2.2.2.0/24 from P1 to P2 and advertise P3 5.5.5.0/24 to P2.
    Is this possible?
    How will i go about the config?
    Thanks to advise.
    Steve

    Steve,
    It depends on how you're peered up and if you have any filtering between you. By default, BGP will advertise anything that's in its table. For example, if you have:
    P1 -- P2 -- P3
    And you advertise 1.1.1.0/24 from P1 to P2, P2 will advertise to P3. There are caveats though. That's with an ebgp peering (Different AS numbers). If you have all of these in ibgp (same AS number), P1 will advertise to P2, but P2 will not advertise to P3 because it was an ibgp learned route. In that scenario, you'd have to have a full mesh of peerings or use confederations/route reflectors.
    HTH,
    John

  • Possibility of drawing numbers on java bouncing balls?

    Can anyone show me how to put numbers on these moving balls in my code. I need the numbers 1-60 on them. I have two sets the red and white. Here is my code. Any help is appreciated. I am trying to write a program to represent the powerball.
    import java.awt.*;
    import java.applet.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.Rectangle;
    class CollideBall{
    int width, height;
    public static final int diameter=20;
    //coordinates and value of increment
    double x, y, xinc, yinc, coll_x, coll_y;
    boolean collide;
    Color color;
    Graphics g;
    Rectangle r;
    //the constructor
    public CollideBall(int w, int h, int x, int y, double xinc, double yinc, Color c){
    width=w;
    height=h;
    this.x=x;
    this.y=y;
    this.xinc=xinc;
    this.yinc=yinc;
    color=c;
    r=new Rectangle(150,80,130,90);
    public double getCenterX() {return x+diameter/2;}
    public double getCenterY() {return y+diameter/2;}
    public void alterRect(int x, int y, int w, int h){
    r.setLocation(x,y);
    r.setSize(w,h);
    public void move(){
    if (collide){  
    double xvect=coll_x-getCenterX();
    double yvect=coll_y-getCenterY();
    if((xinc>0 && xvect>0) || (xinc<0 && xvect<0))
    xinc=-xinc;
    if((yinc>0 && yvect>0) || (yinc<0 && yvect<0))
    yinc=-yinc;
    collide=false;
    x+=xinc;
    y+=yinc;
    //when the ball bumps against a boundary, it bounces off
    //ball width is 6 so if the ball becomes less then 6 it is touching the frame
    //if ball is greater than the entire width-the diameter of the rectangle, then the ball is just touching the frame of the rectangle and must switch to negative to go in opposit direction
    if(x<6 || x>width-diameter){
    xinc=-xinc;
    x+=xinc;
    //same thing as about just about the Y-axis instead of the x-axis
    if(y<6 || y>height-diameter){
    yinc=-yinc;
    y+=yinc;
    public void hit(CollideBall b){
    if(!collide){
    coll_x=b.getCenterX();
    coll_y=b.getCenterY();
    collide=true;
    public void paint(Graphics gr){
    g=gr;
    g.setColor(color);
    //the coordinates in fillOval have to be int, so we cast
    //explicitly from double to int
    g.fillOval((int)x,(int)y,diameter,diameter);
    //Draws half white and half dark gray arc around the balls to give light and shadow effect
    g.setColor(Color.white);
    g.drawArc((int)x,(int)y,diameter,diameter,45,180);
    g.setColor(Color.darkGray);
    g.drawArc((int)x,(int)y,diameter,diameter,225,180);
    public class BouncingBalls extends Applet implements Runnable { 
    Thread runner;
    Image Buffer;
    Graphics gBuffer;
    CollideBall ball[];
    //Obstacle o;
    //how many balls?
    static final int MAX=60;
    boolean intro=true,drag,shiftW,shiftN,shiftE,shiftS;
    boolean shiftNW,shiftSW,shiftNE,shiftSE;
    int xtemp,ytemp,startx,starty;
    int west, north, east, south;
    public void init() {  
    Buffer=createImage(getSize().width,getSize().height);
    gBuffer=Buffer.getGraphics();
    ball=new CollideBall[MAX];
    int w=getSize().width-5;
    int h=getSize().height-5;
    //our balls have different start coordinates, increment values
    //(speed, direction) and colors
    for (int i = 0;i<30;i++){
    ball=new CollideBall(w,h,48+i,500+i,1.5,2.0,Color.white);
    ball[i+30]=new CollideBall(w,h,890+i,200+i,1.5,2.0,Color.red);
    public void start(){
    if (runner == null) {
    runner = new Thread (this);
    runner.start();
    /* public void stop(){
    if (runner != null) {
    runner.stop();
    runner = null;
    public void run(){
    while(true) {
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    try {runner.sleep(15);}
    catch (Exception e) { }
    //move our balls around
    for(int i=0;i<MAX;i++){
    ball[i].move();
    handleCollision();
    repaint();
    boolean collide(CollideBall b1, CollideBall b2){
    double wx=b1.getCenterX()-b2.getCenterX();
    double wy=b1.getCenterY()-b2.getCenterY();
    //we calculate the distance between the centers two
    //colliding balls (theorem of Pythagoras)
    double distance=Math.sqrt(wx*wx+wy*wy);
    if(distance<b1.diameter)
    return true;
    return false;
    private void handleCollision(){
    //we iterate through all the balls, checking for collision
    for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++){
    if(i!=j){         
    if(collide(ball[i], ball[j])){  
    ball[i].hit(ball[j]);
    ball[j].hit(ball[i]);
    public void update(Graphics g){
    paint(g);
    public void paint(Graphics g) { 
    gBuffer.setColor(Color.lightGray);
    gBuffer.fillRect(0,0,getSize().width,getSize().height);
    gBuffer.draw3DRect(5,5,getSize().width-10,getSize().height-10,false);
    //paint our balls
    for(int i=0;i<MAX;i++)
    ball[i].paint(gBuffer);
    g.drawImage (Buffer,0,0, this);
    Thanks again

    this.user wrote:
    JakeG27 post your code within the code tab it will be more clear.
    You can do this by clicking on CODE when you do this will appear { code} { code} post your code inbetween those to tags.
    ie
    { code} code... { code}
    and it will look like this
    code
    This must be the first sensible post you've ever made. At least you're able to copy someone else's response and pretend you know something.

  • Previewing Pages document in Preview shows page numbers incorrectly

    Previewing Pages (5.2) document in Preview (7.0) shows page numbers incorrectly. Regardless of starting page number preview shows as Page 1.
    Suggestions appreciated...

    That appears to be YABIP5 (Yet Another Bug In Pages 5].
    Pages .09 documents are fine.
    No prizes however for finding bugs in Pages 5/5.2 it's swarming with them.
    Peter

Maybe you are looking for

  • PDF output vs. RTF Output

    I have a few form fields in my template which say only display this line if the data exists. When I output the report as PDF the lines with no data are hidden as I'd expect. When I output as RTF the lines are still there. Also, unticking the 'Allow r

  • Ipad3 problem

    Can't find the open in option for a webpage that wont open on ipad

  • New Apple Mavericks and Blackberry Sysn

    Hi, I noticed that after upgrading to Mavericks Apple's sync services (iSync etc.) are no longer there. Trying to reinstal Isyn also failed. Apple support confirmed that and could not offer any workaround. In other words - Blackbery App in general wo

  • After Even Process Chain

    I have a process chain ‘B’ scheduled in mode ‘After Event: Z_CHAIN’ How can I see what is ‘Z_CHAIN’? I try to see this with SE37 and SE38 but with out any happy result. Thank you in advance.

  • 11.5.9 - Forgot Password

    Hi, Is there any functionality in 11.5.9 to use "Forgot Password" in the login page?. I know this functionality is available from 11.5.10 onwards. Thanks in advance.